Help with Algorithm for inserting data into Binary Tree

This is a discussion on Help with Algorithm for inserting data into Binary Tree within the C++ Programming forums, part of the General Programming Boards category; I need help with the algorithm for inserting a text file into a Binary Tree, the pseudo-code will do just ...

  1. #1
    Shake Zula- The Mic Rula!
    Join Date
    Sep 2004
    Posts
    69

    Help with Algorithm for inserting data into Binary Tree

    I need help with the algorithm for inserting a text file into a Binary Tree, the pseudo-code will do just fine, or even the C++ code if anyone feels frisky... thanks guys.

  2. #2
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Code:
    BinaryTree myTree;
    myTree.insert("I'm not feeling frisky");
    myTree.insert("I'm not doing someone else's homework");
    myTree.display();
    If you need this kind of information, there are hundreds of binary tree tutorials and bits of example code all around the web. Why not try G O O G L E ?!

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Data - Object to be inserted in tree
    Node - your current node oyu're in

    1) Set Node to Root of tree
    2) If Data.Value < Node.Value goto 3) else goto 6)
    3) if Node.Left is empty, insert Data as left child of Node, stop
    4) Set Node to Node.Left
    5) goto 2)
    6) if Node.Right is empty, insert Data as right child of Node, stop
    7) Set Node to Node.Right
    8) goto 2)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. binary tree token problem
    By OldSchool in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2006, 10:42 PM
  3. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 11:47 PM
  4. How to program a data tree? (not binary)
    By Captain Penguin in forum C++ Programming
    Replies: 5
    Last Post: 12-30-2002, 02:25 PM

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