$12.00 C++ Program To Generate N-Node Binary Search Tree. Compiled, Tested, Works. Detailed Comments
- This tutorial was purchased 7 times and rated A+ by students like you.
- Posted on Feb 10, 2009 at 6:14:49PM
A:
Preview: ... ><br> int value;<br><br> Node* left;<br> Node* right;<br>};<br><br>Node::Node(int i)<br>{<br> value = i;<br> left = NULL;<br> right = NULL;<br>}<br><br><br>class BinaryTree<br>{<br> public:<br> BinaryTree();<br> ~BinaryTree();<br><br> void insert(int i);<br><br> //To clean up the memory after we're done<br> void clear();<br> <br> //Ways of displaying all of the keys in the tree starting at root<br> void preorder();<br> void inorder();<br> void postorder();<br> <br> //How many levels our tree is from the root<br> int getLevels();<br> <br> //Search to see if the tree contains a value<br> bool findValue(int i);<br><br> private:<br> Node* root;<br> <br> //Ways of displaying all of the keys in the tree from node n<br> void preorder(Node* n);<br> void inorder(Node* n);<br> void postorder(Node* n);<br><br> //For clearing the tree<br> void removeNode(Node*& n);<br><br> //Private helper of insert, starts at private Node *root.<br> void insert(Node*& n, int i);<br> <br> //How many levels our tree is from node n<br> int levels(Node* n);<br> <br> //Search to see if the tree contains a value<br> bool findValue(Node* n, int i);<br><br>};<br><br>BinaryTree::BinaryTree()<br>{<br> root = NULL;<br>}<br><br>BinaryTree::~BinaryTree()<br>{<br> //Clean the tree up after we're done<br> removeNode(root);<br>}<br><br><br>v ...
The full tutorial is about 1811 words long plus attachments.
Attachments:
bstree.cpp (6K)