int main(int argc, char **argv) { /* Déclarons 3 listes chaînées de façons différentes mais équivalentes */ arbre *a = creerArbre(1); arbre *b = creerArbre(8); ajouterEnfant(a,2); ajouterEnfant(a,4); ajouterEnfant(b,16); embranche(a,b); afficherArbre(a); return 0; }
int main(void) { Arbre *a = creerArbre(5); printf("5 est présent : %d\n", recherche(a, 5)); printf("5 est présent : %d\n", recherche2(a, 5)); printf("%d", nbCles(a)); return EXIT_SUCCESS; }
Arbre inserer(Arbre pere, Direction direction, Couleur couleur) { Arbre nouveau = creerArbre(); nouveau->couleur = couleur; if(pere == NULL) { return nouveau; } pere->fils[direction] = nouveau; return pere; }
Arbre loadImage2(char * name,int h_img, int x,int y,int h,Arbre pere) { assert(pere != NULL); if(h == 1) { Arbre res = creerArbre(); res->couleur = readCouleur(name,x,y,h_img); return res; } pere->fils[NO] = creerArbre(); pere->fils[NE] = creerArbre(); pere->fils[SO] = creerArbre(); pere->fils[SE] = creerArbre(); pere->fils[NO] = loadImage2(name,h_img,x,y+h/2, h/2,pere->fils[NO]); pere->fils[NE] = loadImage2(name,h_img,x+h/2,y+h/2, h/2,pere->fils[NE]); pere->fils[SO] = loadImage2(name,h_img,x,y,h/2, pere->fils[SO]); pere->fils[SE] = loadImage2(name,h_img,x+h/2,y, h/2,pere->fils[SE]); return pere; }
Arbre loadImage(char * name,int h_img) { Arbre pere = creerArbre(); pere = loadImage2(name,h_img,0,0,h_img,pere); return pere; }
void ajouterEnfant(arbre *a, int e){ arbre *ptr = creerArbre(e); ptr->frere = a->enfant; a->enfant = ptr; a->nbE++; }