This preview shows pages 1–3. Sign up to view the full content.
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
This note was uploaded on 02/04/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue UniversityWest Lafayette.
 Fall '08
 Staff

Click to edit the document details