Building Binary Tree

This is a discussion on Building Binary Tree within the C++ Programming forums, part of the General Programming Boards category; Hi guys.. I want to build a Binary Tree (Not Binary Search Tree) which is complete using Linked List.. Any ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    23

    Building Binary Tree

    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);             
                           }
    };

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Quote Originally Posted by 7heavens View Post
    Hi guys.. I want to build a Binary Tree (Not Binary Search Tree) which is complete using Linked List..
    What on earth does that all mean?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21