Binary Search Tree : Insertion

Back to Problems List View Submissions

Problem Statment
You are given a pointer to the root of a binary search tree and a value to be inserted into the tree. Insert this value into its appropriate position in the binary search tree and return the root of the updated binary tree. You just have to complete the function.

Input Description
You are given a function, node * insert (node * root ,int value) { } node is defined as : struct node { int data; node * left; node * right; }node;

Output Description
Return the root of the binary search tree after inserting the value into the tree.

Sample Input

/ 2 7
/ 1 3
The value to be inserted is 6.

Sample Output

/ 2 7
/ /
1 3 6

Code Editor

  //Your code goes here.