Thread: Nodes

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    8

    Exclamation Nodes

    Hi
    can a single node have have multiple data types and information in it stored?

    im doing a binary tree program

    and for each node i need to enter details such as

    name
    key
    description
    etc

    thankyou

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Marcello
    can a single node have have multiple data types and information in it stored?
    Yes. You are the class designer, so you have the power to make it so.

    Quote Originally Posted by Marcello
    im doing a binary tree program

    and for each node i need to enter details such as

    name
    key
    description
    etc
    It may be better to create a class for these details (e.g., name of what? The "what" could then be the class name.) Your nodes will then just contain objects of this class type.
    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

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    ok i created this class , is that what you mean?

    Code:
    setPersonalInfo(root, name, key, desc);
    }
    {
    binarySearchTree tmp;
    tmp.treeInsert(root, name);
    tmp.treeInsert(root, key);
    tmp.treeInsert(root, desc);
    }
    Code:
    public:
    void setPersonalInfo(treeNode *&root, string name, string key, string desc);
    ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No. What I am suggesting is that you write a binary tree class that works with data that are objects of int type. You implement and test it. Later, you replace these objects of int type with objects of type T, where T is a class that contains name, key, description, etc. You don't have to do it this way, but it will make things easier for you.
    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

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    Quote Originally Posted by laserlight View Post
    No. What I am suggesting is that you write a binary tree class that works with data that are objects of int type. You implement and test it. Later, you replace these objects of int type with objects of type T, where T is a class that contains name, key, description, etc. You don't have to do it this way, but it will make things easier for you.
    i thankyou for your reply i really do appricate it , but to be honest im a bit short on time so i cant reconstruct my program to much.... is there anyway this can be done through the way i have it at the momment? to combine all my different strings into one node?

    thanks

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    Bump , how do i put 5 different strings of information into a single node ?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Marcello View Post
    i thankyou for your reply i really do appricate it , but to be honest im a bit short on time so i cant reconstruct my program to much.... is there anyway this can be done through the way i have it at the momment? to combine all my different strings into one node?

    thanks
    Quote Originally Posted by Marcello View Post
    Bump , how do i put 5 different strings of information into a single node ?
    It's exactly like Laserlight said. A node would contain one piece of data. If you want your node to contain several pieces of data, then combine those pieces of data into a class or struct and use that struct or class as the node data.
    This is the easiest way of doing it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    Thankyou i love yous!!!!!!!!

  9. #9
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    Like this?

    Code:
    class binarySearchTree
    {
    public:
    binarySearchTree(); 
    
    void treeInsert(treeNode *&root, string newItem, string oldItem, string ollItem, string neeItem, string hapItem);



    Code:
     
    binarySearchTree::binarySearchTree() :root(NULL)
    {
    }
    void binarySearchTree::treeInsert(treeNode *&root, string newItem, string oldItem, string ollItem, string neeItem, string hapItem)
    {
    if(root == NULL)
    {
    root = new treeNode(newItem), (oldItem), (ollItem),  (neeItem),  (hapItem);
    return;
    }
    else if (newItem, oldItem,  ollItem,  neeItem,  hapItem < root->data)
    {
    treeInsert(root->left, newItem,  oldItem,  ollItem,  neeItem,  hapItem);
    }
    else
    {
    Last edited by Marcello; 10-30-2011 at 11:12 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nodes
    By firefly in forum C++ Programming
    Replies: 8
    Last Post: 07-02-2005, 06:38 AM
  2. nodes
    By Zypo in forum C++ Programming
    Replies: 6
    Last Post: 11-08-2003, 04:56 PM
  3. First and Last Nodes
    By HybridM in forum C++ Programming
    Replies: 8
    Last Post: 09-27-2003, 03:47 AM
  4. Finding Nodes on a BST
    By s0ul2squeeze in forum C++ Programming
    Replies: 0
    Last Post: 05-05-2002, 01:25 PM
  5. Help w/nodes
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2002, 08:09 PM