multiple strings into a Node

Hi fellas

i have my code here and im trying to get my binary tree to function. it compiles although its not functining the best. how do i get the five strings of information to be stored into one node .. i have tried everything and i cant work it out, please help

Like this?

1
2
3
4
5
6
7
 class binarySearchTree
 {
 public:
 binarySearchTree(); 

void treeInsert(treeNode *&root, string newItem, string oldItem, string ollItem, string neeItem, string hapItem); 





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  
 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
 {
 
The thing that goes after new is a constructor call and a constructor is basically a function. No function is called as fun(arg1), (arg2), ...
If there is a constructor with 5 string arguments, you just pass them as to any function: new treeNode(newItem, oldItem, ...
If there isn't and what you want is concatenation, use + operator: new treeNode(newItem+" "+oldItem+...
Same goes for the if on line 12. What ',' does is ignore it's left argument so that line is just hapItem < root->data.
thanks for your reply

do u mean like this? .. i cant get it working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
binarySearchTree::binarySearchTree() :root(NULL)
{
}
void binarySearchTree::treeInsert(treeNode *&root, string newItem, string oldItem, string ollItem, string neeItem, string hapItem)
//Add an item to the binary sort tree
//to which the parameter 'root' refers.
{
if(root == NULL)
{
//the tree is empty. Set root to point to a new node containing
//the new item. This becomes the only node in the tree.

root = new treeNode(newItem + oldItem + ollItem+  neeItem+  hapItem);
//left and right subtrees of root are automatically set to NULL by 
//the constructor
return;
}
else if (newItem + oldItem + ollItem+  neeItem+  hapItem < root->data)
{
treeInsert(root->left,newItem + oldItem + ollItem+  neeItem+  hapItem);
}
else
{
treeInsert(root->newItem + oldItem + ollItem+  neeItem+  hapItem );
}
}//end treeInsert 
void treeInsert(treeNode *&root ,string newItem, string oldItem, string ollItem, string neeItem, string hapItem);
Like Marcello says, look at what you're passing to treeInsert. Then compare it with how you declared treeInsert.
Topic archived. No new replies allowed.