


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



int h(struct AVLnode * current) {if (current == 0) return - 1; return current->height;} void setHeight (struct AVLnode * current) { int lch = h(current->left); int rch = h(current->right); if (lch < rch) current->height = 1 + rch; else current->height = 1 + lch; }
struct AVLnode * AVLnodeAdd (struct AVLnode* current, EleType newValue) { struct AVLnode * newnode; if (current == 0) { newnode = (struct AVLnode ) malloc(sizeof(struct AVLnode)); assert(newnode != 0); newnode->value = newValue; newnode->left = newnode->right = 0; return balance(newnode); } else if (LT(newValue, current->value)) current->left = AVLnodeAdd(current->left, newValue); else current->right = AVLnodeAdd(current->right, newValue); return balance(current); / <- NEW the call on balance */ }
struct AVLnode { EleType value; struct AVLnode *left; struct AVLnode *right; int height; };
struct AVLnode * rotateLeft (struct AVLnode * current) { struct AVLnode * newtop = n->right; n->right = newtop->left; newtop->left = n; setHeight(n); setHeight(newtop); return newtop; } struct AVLnode * rotateRight (struct AVLnode * current) { struct AVLnode * newtop = n->left; n->left = newtop->right; newtop->right = n; setHeight(n); setHeight(newtop); return newtop; }