We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1622f9b commit 1cd0710Copy full SHA for 1cd0710
Trees/BST.cpp
@@ -14,20 +14,21 @@ struct bst
14
};
15
16
// insertion of elements
17
-void insert(bst **root, int x)
18
-{
19
- if (*root == NULL)
+bst* insert(bst* root, int x) {
+ if(root==NULL)
20
{
21
- *root = new bst(x);
22
- }
23
- else if (x < (*root)->data)
+ root=new bst(x);
+ return root;
+ }
+ else if(x>root->data)
24
25
- insert(&((*root)->lc), x);
+ root->rc=insert(root->rc,x);
26
}
27
- else if (x > (*root)->data)
+ else
28
29
- insert(&((*root)->rc), x);
+ root->lc=insert(root->lc,x);
30
31
32
33
34
// searching the elements
@@ -197,4 +198,4 @@ int main()
197
198
199
bst *root = NULL;
200
return 0;
-}
201
+}
0 commit comments