This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: prev = n; // save programs value if(keykey){ n = n>left; }else{ n = n>right; } } if(n!=NULL){ //key exsists, replace value. n > value = value; return true; } // key does not exsist n = new TreeNode; n>key = key; n>value = value; n>left = NULL; n>right = NULL; //check if tree was empty if(prev == NULL){ //the tree is empty root = n; return false; } // the tree is not empty if(keykey){ prev > left = n; }else{ prev > right = n; } return false; } the add function does not guarantee that the tree will be balanced We are going to see AVL trees that perform rebalancing after every insertion or removal if necessary....
View
Full Document
 Fall '08
 Staff
 int key, int struct TreeNode, int key,int value

Click to edit the document details