Commit c8dbffe1779a0d219dc80412f1ccc515f22f053c
1 parent
7a8ec0f4
second commit
Showing
1 changed file
with
81 additions
and
5 deletions
Show diff stats
projet.c
1 | -typedef struct node | |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | + | |
4 | + | |
5 | + | |
6 | +typedef struct noeud | |
2 | 7 | { |
3 | - int key; | |
4 | - struct node *left; | |
5 | - struct node *right; | |
6 | -} node ; | |
8 | + int valeur; | |
9 | + struct noeud *gauche; | |
10 | + struct noeud *droite; | |
11 | +} noeud ; | |
12 | + | |
13 | + | |
14 | + | |
15 | + | |
16 | + | |
17 | +void print_arbre(noeud *arbre) | |
18 | +{ | |
19 | + if (arbre==NULL) | |
20 | + printf("NULL\n"); | |
21 | + else if(arbre!=NULL) | |
22 | + { | |
23 | + printf("%d\n",arbre->valeur); | |
24 | + | |
25 | + if (arbre->gauche != NULL) | |
26 | + print_arbre(arbre->gauche); | |
27 | + // printf("\n");} | |
28 | + else if(arbre->gauche == NULL) | |
29 | + printf("NULL\t"); | |
30 | + | |
31 | + if (arbre->droite != NULL) | |
32 | + print_arbre(arbre->droite); | |
33 | + // printf("\n");} | |
34 | + else if (arbre->droite != NULL) | |
35 | + printf("NULL\t"); | |
36 | + } | |
37 | + | |
38 | + | |
39 | +} | |
40 | + | |
41 | +void insertion(noeud ** arbre, int v){ | |
42 | + if (*arbre==NULL) /* si le noeud n’existe pas, on le crée */ | |
43 | + { | |
44 | + *arbre=(noeud*) malloc(sizeof(noeud)); | |
45 | + (*arbre)->valeur=v; | |
46 | + (*arbre)->gauche=NULL; | |
47 | + (*arbre)->droite=NULL; | |
48 | + } | |
49 | +} | |
50 | + | |
51 | +// else | |
52 | +// { | |
53 | +// if (v>(*arbre)->valeur) | |
54 | +void insertionD(noeud ** arbre, int v){ | |
55 | + insertion(&(*arbre)->droite,v); /* aller a droite */ } | |
56 | +// else | |
57 | +void insertionG(noeud ** arbre, int v){ | |
58 | + insertion(&(*arbre)->gauche,v); /* aller a gauche */ } | |
59 | + | |
60 | + | |
61 | + | |
62 | +int main(){ | |
63 | + | |
64 | + | |
65 | + | |
66 | + noeud *Arbre = NULL; | |
67 | + | |
68 | + | |
69 | + | |
70 | + insertion(&Arbre, 303); | |
71 | + insertionD(&Arbre, 304); | |
72 | + insertionG(&Arbre, 305); | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + print_arbre(Arbre); | |
78 | + // FILE* fichier = NULL; | |
79 | + //fichier = fopen("texte.txt","r"); | |
80 | + return 0; | |
81 | + | |
82 | +} | ... | ... |