Just look for it 2 0 its just another data collection

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: general binary search tree. 8 7 It goes where you expect it to be. So, now let's implement a BinaryTree structure BinaryTree (really binary search tree, but that's too long a title). 6 9 struct struct node; typedef node *nodePtr; struct node { void* data; nodePtr left, right; }; nodePtr root; void void void bool bool init_tree(nodePtr root); // // initialization destroy_tree(nodePtr root); // destruction Insert(nodePtr root, void* data); Locate(nodePtr root, void* data, void* fdata); Delete(nodePtr root, void* data); 5 We'll need a comparison function int TreeDataCmp(void* data1,void* data2); for relative positioning. like the linked list, the only difference is how the member functions operate. Initialize set root to 0 root Locate Set current node to be root of tree WHILE data is not at current node IF data required is in the left sub-tree subset current node to root of left sub-tree (the left child) subELSE set current node to root of right sub-tree (the right child) sub- Their outward appearance is the same. Although this is iterative, we can also write it recursive – much more usual. Here is a function which will perform the task. We...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online