Salut, j'ai un problème : comment implémenter une arbre binaire en Pascal ?
J'ai beaucoup essayé mais je n'y arrive pas.
Voilà mon code source ; SVP aidez-moi pour juste implémenter l'arbre et moi je vais faire les parcours prefixé, postfixé et infixé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
            a
           /
          b
         / \
       e    c
       \      \
        f     d
         \    /
          g  i
           \
            h
Voilà le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Program Arbre_ABR;
Type
       Arbre= ^Noeud;
       Noeud = Record
                racine: char;
                FGauche : Arbre;
                FDroit  : Arbre;
               End;
var pr:Arbre;
 
 
PROCEDURE CREER ( racine : char ; VAR Abr : Arbre);
BEGIN
 New(Abr);
 Abr^.racine:= racine;
 Abr^.FGauche:= NIL;
 Abr^.FDroit:= NIL;
END;
 
FUNCTION GAUCHE ( Abr : Arbre ) : Arbre;
BEGIN
 GAUCHE:= Abr^.FGauche;
END;
 
FUNCTION DROIT ( Abr : Arbre ) : Arbre;
BEGIN
 DROIT:= Abr^.FDroit;
END;
 
procedure postfixe (Abr: Arbre);
  begin 
    if Abr <> nil then
        begin 
          postfixe(GAUCHE(Abr));
          postfixe(DROIT(Abr));
          write(Abr^.racine);
        end 
  end;
procedure infixe (Abr: Arbre);
  begin 
    if Abr <> nil then
        begin 
          infixe(GAUCHE(Abr));
          write(Abr^.racine);
          infixe(DROIT(Abr));
        end 
  end;
procedure prefixe (Abr: Arbre);
  begin 
    if Abr <> nil then
        begin 
          write(Abr^.racine);
          prefixe(GAUCHE(Abr));
          prefixe(DROIT(Abr));
        end 
  end;
 
 
function Construit (racine: char; FDroit,FGauche : Arbre): Arbre;
var  Abr: Arbre;
begin 
    new(Abr);
    with Abr^ do
    begin 
        racine:= racine;
        FGauche:= GAUCHE(Abr);
        FDroit:= Droit(Abr);
    end; 
    construit := Abr;
end;
begin
write('enter l"arbre');
CREER('a',pr);
end.
SVP aidez-moi, j'attends votre réponse. Merci.