SE250:lab-6:mgha023
Jump to navigation
Jump to search
minimum
Initially I had this :/*if (node == empty){ return ; } minimum( (*node)->left) ; return node;*/
but that wasn't really right... Then I had:
Node* minimum( Node* node ) { while (*node != empty){ node = &(*node)->left; return node; } return 0; }
maximum
Initially:
/*if (node == empty){ return ; } //else return (*node)-> right; maximum( (*node)->right); */
Finally:
Node* maximum( Node* node ) { while (*node != empty){ node = &(*node)->right; return node; } return 0; }
lookup
Initially:
- if (node == empty){
return; } else lookup((*node)->key, node);*/
Finally:
Node* lookup( int key, Node* node ) { if (*node != empty){ printf("%d\n", (*node)->key); lookup(&(*node)->left); lookup(&(*node)->right); } return 0; }
successor funtion:next_pre
Node* next_pre( Node* node ) { if ((*node)->right != empty){ return next_pre((*node)->right); } return o; }
At this point I found this website Link Binary Search Treehttp://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/binarySearchTree.htm
that had some useful explanation that helped me get a better understanding of what was to be done.
prev_pre
Node* next_pre( Node* node ) { if ((*node)->right != empty){ return next_pre((*node)->right); } return 0; }