Skip to content

Commit 1cd0710

Browse files
authored
Update BST.cpp
1 parent 1622f9b commit 1cd0710

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Trees/BST.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ struct bst
1414
};
1515

1616
// insertion of elements
17-
void insert(bst **root, int x)
18-
{
19-
if (*root == NULL)
17+
bst* insert(bst* root, int x) {
18+
if(root==NULL)
2019
{
21-
*root = new bst(x);
22-
}
23-
else if (x < (*root)->data)
20+
root=new bst(x);
21+
return root;
22+
}
23+
else if(x>root->data)
2424
{
25-
insert(&((*root)->lc), x);
25+
root->rc=insert(root->rc,x);
2626
}
27-
else if (x > (*root)->data)
27+
else
2828
{
29-
insert(&((*root)->rc), x);
29+
root->lc=insert(root->lc,x);
3030
}
31+
return root;
3132
}
3233

3334
// searching the elements
@@ -197,4 +198,4 @@ int main()
197198
{
198199
bst *root = NULL;
199200
return 0;
200-
}
201+
}

0 commit comments

Comments
 (0)