From c8dbffe1779a0d219dc80412f1ccc515f22f053c Mon Sep 17 00:00:00 2001 From: Raouak Haroun Date: Mon, 25 Mar 2019 15:56:11 +0100 Subject: [PATCH] second commit --- projet.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/projet.c b/projet.c index 300f73e..e44fd8f 100644 --- a/projet.c +++ b/projet.c @@ -1,6 +1,82 @@ -typedef struct node +#include +#include + + + +typedef struct noeud { - int key; - struct node *left; - struct node *right; -} node ; + int valeur; + struct noeud *gauche; + struct noeud *droite; +} noeud ; + + + + + +void print_arbre(noeud *arbre) +{ + if (arbre==NULL) + printf("NULL\n"); + else if(arbre!=NULL) + { + printf("%d\n",arbre->valeur); + + if (arbre->gauche != NULL) + print_arbre(arbre->gauche); + // printf("\n");} + else if(arbre->gauche == NULL) + printf("NULL\t"); + + if (arbre->droite != NULL) + print_arbre(arbre->droite); + // printf("\n");} + else if (arbre->droite != NULL) + printf("NULL\t"); + } + + +} + +void insertion(noeud ** arbre, int v){ + if (*arbre==NULL) /* si le noeud n’existe pas, on le crée */ + { + *arbre=(noeud*) malloc(sizeof(noeud)); + (*arbre)->valeur=v; + (*arbre)->gauche=NULL; + (*arbre)->droite=NULL; + } +} + +// else +// { +// if (v>(*arbre)->valeur) +void insertionD(noeud ** arbre, int v){ + insertion(&(*arbre)->droite,v); /* aller a droite */ } +// else +void insertionG(noeud ** arbre, int v){ + insertion(&(*arbre)->gauche,v); /* aller a gauche */ } + + + +int main(){ + + + + noeud *Arbre = NULL; + + + + insertion(&Arbre, 303); + insertionD(&Arbre, 304); + insertionG(&Arbre, 305); + + + + + print_arbre(Arbre); + // FILE* fichier = NULL; + //fichier = fopen("texte.txt","r"); + return 0; + +} -- libgit2 0.21.2