Although this is iterative we can also write it

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: call it with the actual root. We assume that the tree is non-empty. nonThe return value of 0 is a not-found result. notAll we have to do is use this function in Locate Locate function. nodePtr FindNode(void* data, nodePtr& root) { int Result = TreeDataCmp(data,root->data); TreeDataCmp(data,rootif (Result == 0) (Result 0) return root; if (Result < 0 && root->left != 0) rootreturn FindNode(data,root->left); FindNode(data,rootelse if (Result > 0 && root->right != 0) rootreturn FindNode(data,root->right); FindNode(data,rootreturn 0; } You can implement a non-recursive version of nonFindNode() FindNode(). bool Locate(nodePtr root, void* data, void* fdata) { nodePtr foundNode = FindNode(data, root); if (foundNode != 0) { fdata = foundNode->data; foundNodereturn true; } else return false; } Earlier we said that the process of adding a new node was almost identical to finding a data value. You'll see how more complex it seems. And so Insert is performed in a similar manner. Inse...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online