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
| #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct arbre *ptr_arbre;
typedef struct arbre
{
int val;
ptr_arbre fg;
ptr_arbre fd;
}arbre;
typedef ptr_arbre t_ptr_arbre ;
t_ptr_arbre nvArbre(int val, t_ptr_arbre fg, t_ptr_arbre fd)
{
t_ptr_arbre temp_arbre;
temp_arbre=(ptr_arbre)malloc(sizeof(arbre));
temp_arbre->val=val;
temp_arbre->fg=fg;
temp_arbre->fd=fd;
return temp_arbre;
}
void affichage_prefixe(t_ptr_arbre a) // parcours de premier passage (par exemple)
{
if(a!=NULL)
{
printf("%d - ", a->val);
affichage_prefixe(a->fg);
affichage_prefixe(a->fd);
}
}
int main(){
t_ptr_arbre arbre,b,c,d,e,f,g;
f=nvArbre(2,NULL,NULL);
g=nvArbre(9,NULL,NULL);
d=nvArbre(3,NULL,NULL);
e=nvArbre(7,NULL,NULL);
b=nvArbre(8,d,e);
c=nvArbre(21,f,g);
arbre=nvArbre(5,b,c);
affichage_prefixe(arbre);
system("PAUSE");
return (0);
} |
Partager