Hi guys.. I want to build a Binary Tree (Not Binary Search Tree) which is complete using Linked List.. Any ideas? I have a search function implemented below which returns you a TreeNode pointer if it finds the element. I can't test it out coz I need to insert elements to test it.. How do you implement this insert function?? Any help is greatly appreciated.
Code:
class BT
{
private:
struct TreeNode
{
int key;
//Associated data type can be declared here
TreeNode *left, *right;
};
TreeNode*_root;
public:
TreeNode* InsertNode(TreeNode*T, int x)
{
//DON'T KNOW HOW TO INSERT!!!!
}
TreeNode* SearchR(TreeNode* T,int key)
{
if (T==NULL)
return NULL;
if (key == T->key)
{
return T;
}
else if (SearchR(T->right,key))
return SearchR(T->right,key);
else if(Search(T->left,key))
return SearchR(T->left,key);
}
};