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
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
Yes. You are the class designer, so you have the power to make it so.Originally Posted by Marcello
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.Originally Posted by Marcello
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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);
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
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.
Thankyou i love yous!!!!!!!!
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.