int main(){ struct node *last = NULL; insertEmpty(&last,3); insertBeginning(&last,1); insertEnd(&last,4); insertBetween(&last,1,2); printList(last); }
int AVLTree::Insert (AVLTree * &racine, int insertType, AVLTree * insertL, AVLTree * insertR) { if (racine == NULL) { racine = this; return avl_no_err; } else { if (insertType == not_found) { // cout << "pb avec l'arbre de raster\n"; return avl_ins_err; } else if (insertType == found_on_left) { if (insertR == NULL || insertR->child[LEFT]) { // cout << "ngou?\n"; return avl_ins_err; } insertR->child[LEFT] = this; parent = insertR; insertOn(LEFT, insertR); } else if (insertType == found_on_right) { if (insertL == NULL || insertL->child[RIGHT]) { // cout << "ngou?\n"; return avl_ins_err; } insertL->child[RIGHT] = this; parent = insertL; insertOn(RIGHT, insertL); } else if (insertType == found_between) { if (insertR == NULL || insertL == NULL || (insertR->child[LEFT] != NULL && insertL->child[RIGHT] != NULL)) { // cout << "ngou?\n"; return avl_ins_err; } if (insertR->child[LEFT] == NULL) { insertR->child[LEFT] = this; parent = insertR; } else if (insertL->child[RIGHT] == NULL) { insertL->child[RIGHT] = this; parent = insertL; } insertBetween (insertL, insertR); } else if (insertType == found_exact) { if (insertL == NULL) { // cout << "ngou?\n"; return avl_ins_err; } // et on insere if (insertL->child[RIGHT]) { insertL = insertL->child[RIGHT]->leafFromParent(insertL, LEFT); if (insertL->child[LEFT]) { // cout << "ngou?\n"; return avl_ins_err; } insertL->child[LEFT] = this; this->parent = insertL; insertBetween (insertL->elem[LEFT], insertL); } else { insertL->child[RIGHT] = this; parent = insertL; insertBetween (insertL, insertL->elem[RIGHT]); } } else { // cout << "code incorrect\n"; return avl_ins_err; } } return avl_no_err; }