Binary tree help!!!

hi guys, I need your help i took from internet a code for insert nodes in a tree
but its for search binary tree
i just wanna insert this values {1,2,3,4,5,6,7} in a tree
graphically is like this



here is the piece of code i need to modify, i think the create node method is ok, the problem is with the insert

1 is the root, 2 and 3 are father of 4,5 and 6,7 respectively
1
2
3
            1
    2                 3
4       5         6      7


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  TRE createNode(int x)
{
     ABB newnode = new(struct node);
     newnode->data = x;
     newnode->left = NULL;
     newnode->right = NULL;

     return newnode;
}
void insert(TRE &tree, int x)
{
     if(tree==NULL)
     {
           tree = createNode(x);
     }
     else if(x < tree->data)
          insertar(tree->left, x);
     else if(x > tree->data)
          insert(tree->right, x);
}
Last edited on
Topic archived. No new replies allowed.