print values in a bintree

This is a discussion on print values in a bintree within the C++ Programming forums, part of the General Programming Boards category; I have a struct named myStruct which has the following Code: strcut myStruct() { int code string keyval } I ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    3

    print values in a bintree

    I have a struct named myStruct which has the following

    Code:
    strcut myStruct() {
    
    int code
    string keyval
    }
    I then loaded a txt file into myStruct

    finally I inserted myStruct into a bintree object which I defined in another header file.

    How do I print the data using the bintree??

    For example if I was using a vector, I would use

    Code:
    cout << vector[i].code;

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    3
    Also, I have a find function in my bintree.h

    Code:
          
    bool find(const dataType &findData, dataType &foundData) const {
             if (root == NULL) return false;
             else return root->find(findData, foundData);
    }
    How do I use it in my main program??

    I am quite confused about the parameters that I need to pass to the function.

    Thank You

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,617
    You can overload operator<< to take an ostream& and a const myStruct&.

    Incidentally, if you want to post a code snippet, it should be valid code, or obviously pseudocode. You might also want a more descriptive name than myStruct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    3
    Quote Originally Posted by laserlight View Post
    You can overload operator<< to take an ostream& and a const myStruct&.
    Hi, thx for the reply

    Can you give me a example of how to that?

    I am quite new to programming...

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,617
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-20-2008, 11:58 PM
  3. Replies: 1
    Last Post: 12-30-2007, 09:08 AM
  4. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 09:44 PM
  5. Sending values to a control
    By Zyk0tiK in forum C Programming
    Replies: 6
    Last Post: 12-02-2005, 05:29 PM

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