Thread: Binary Search Tree- Need Advice

  1. #1
    Wen Resu
    Join Date
    May 2003
    Posts
    219

    Binary Search Tree- Need Advice

    I have create a binary search tree, which holds pointers to comparable datatypes.
    the Tree is templated so that the user can specify what data type will be held
    That much wasnt a problem, my tree works.
    What i need help on is what should i do to it next? this is solely a personal project that i'm doing for educational purposes
    I figured i could write a balance member for tree to analyze and balance my tree.
    What else can be done?
    Also, i want to have an easier way to input test data.
    current i am using the command line to do the following
    c:\>bintree > testdata.txt

    which works fine for the input portion of my test driver, but when my program gets to the point where user should enter a number to look up, it just keeps inputting garbage.
    Attached are Node.cpp Tree.cpp and Main.cpp
    Main is a test driver for the class
    the class test is just one i made that is comparable (suports > < == )
    any insight would be nice

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    62
    In main.cpp, right before "cin >> TestNum", insert "cin.ignore()" to get rid of the newline character that is still
    in the input buffer.

  3. #3
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Ah, thank you, but what if i am inputing information manual, how would that affect it, i though cin.ignore() waits on a character to ignore if nothing is in the stream... i shall try it

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    62
    Well, with this modification, your program works. Oh, and by the way:
    std::string works with cin and cout so you don't need to that:

    Code:
    string temp;
    char str[50];
    cin >> str;
    temp = str;
    Instead, try:
    Code:
    cin >> temp;
    And you may want to change
    Code:
    cout << ID << "  " << this->name.c_str() << endl;
    to
    Code:
    cout << ID << "  " << name << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST (Binary search tree)
    By praethorian in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 09:11 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. Binary tree search efficiency
    By ExCoder01 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-23-2003, 10:11 PM
  4. Binary Search Tree, Inserting node
    By cheryl_li in forum C Programming
    Replies: 1
    Last Post: 09-13-2003, 03:53 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM