Nodes

This is a discussion on Nodes within the C++ Programming forums, part of the General Programming Boards category; Hi can a single node have have multiple data types and information in it stored? im doing a binary tree ...

  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
    21,458
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,458
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    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, 03: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

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