We have to find the node containing the value and

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: g removed is a leaf, it is so simple. All we need is locate it. Here's FindNode() from earlier. FindNode() nodePtr FindNode(void* data, nodePtr& root) { int Result = TreeDataCmp(data,root->data); TreeDataCmp(data,root- Here's FindNode() from earlier. FindNode() nodePtr FindNode(void* data, nodePtr& root) { int Result = TreeDataCmp(data,root->data); TreeDataCmp(data,root- if (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; } if (Result == 0) return root; if (Result < 0 && root->left != 0) return FindNode(data,root->left); FindNode(data,rootelse if (Result > 0 && root->right != 0) rootreturn FindNode(data,root->right); FindNode(data,rootreturn 0; } We want to delete the node root when found, root not return it. 9 So we have void DeleteLeaf(void* da...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online