program arbre_genealogique;
const MaxLongueurNom = 30;
type
Genre = (Masculin, Feminin);
Noms = array[1..MaxLongueurNom] of char;
ChaineFreresSoeurs = ^NoeudFrereSoeur;
PersonnePtr = ^Personne;
NoeudFrereSoeur = record
FrereOuSoeur: PersonnePtr;
FrereSoeurSuivant: ChaineFreresSoeurs;
end; {NoeudFrereSoeur}
Personne = record
Nom: Noms;
Prenom: Noms;
Sexe: Genre;
Epoux: PersonnePtr;
FreresEtSoeurs: ChaineFreresSoeurs;
Enfants: ChaineFreresSoeurs;
end; {Personne}
function NouvellePersonne(SonNom, SonPrenom: Noms;
SonSexe: Genre):
PersonnePtr;
var laPersonne: PersonnePtr;
begin
new(laPersonne);
with laPersonne^ do begin
Nom := SonNom;
Prenom := SonPrenom;
Sexe := SonSexe;
Epoux := nil;
FreresEtSoeurs := nil;
end; {with}
NouvellePersonne := laPersonne;
end; {NouvellePersonne}
procedure Epouse(epoux1, epoux2: PersonnePtr);
begin
epoux1^.Epoux := epoux2;
epoux2^.Epoux := epoux1;
end; {Epoux}
procedure AjouteEnfant(Parent, Enfant: PersonnePtr);
var NouveauNoeud, EnfantCourant, EnfantPrecedent: ChaineFreresSoeurs;
begin
new(NouveauNoeud);
with NouveauNoeud^ do begin
FrereOuSoeur := Enfant;
FrereSoeurSuivant := nil;
end; {with}
EnfantCourant := Parent^.Enfants;
if EnfantCourant = nil then begin
{Ce nouvel Enfant est leur premier Enfant}
Parent^.Enfants := NouveauNoeud;
if Parent^.Epoux <> nil then
Parent^.Epoux^.Enfants := NouveauNoeud;
Enfant^.FreresEtSoeurs := NouveauNoeud;
end {if}
else begin
Enfant^.FreresEtSoeurs := EnfantCourant;
{cherche le dernier Enfant}
while EnfantCourant <> nil do begin
EnfantPrecedent := EnfantCourant;
EnfantCourant := EnfantCourant^.FrereSoeurSuivant;
end; {while}
EnfantPrecedent^.FrereSoeurSuivant := NouveauNoeud;
end; {else}
end; {AjouteEnfant}
Sur la base des déclarations et procédures ci-dessus, qui permettent de construire un arbre généalogique:
procedure ImprimePetitsEnfants(LaPersonne: PersonnePtr);
Site Hosting: Bronco