BETA

Difficulty Level: Easy

Submissions: 10733 Accuracy:

26.16%

Insert a node in a BST (Function Problem)
     

Given a Binary Search Tree (BST) your task is to complete the function insert which inserts a node in the BST.
You should not read any input from stdin/console. There are multiple test cases. For each test case, this method will be called individually.

Input (only to be used for Expected Output):
The first line of the input contains an integer 'T' denoting the number of test cases. Then 'T' test cases follow. Each test case consists of three lines. Description of  test cases is as follows:
The First line of each test case contains an integer 'N' which denotes the no of nodes to be inserted in the BST.   .
The Second line of each test case contains 'N' space separated values  of the nodes to be inserted in the BST.

Output:
You are required to complete the function insert which takes two arguments. The first being the root of the tree, and an integer 'x'denoting the node to be inserted to the BST . 

Constraints:
1 <= T <= 100
1 <= N <= 100


Example:
Input

2
7
2 81 87 42 66 90 45 
4
6 7 9 8

Output
2 42 45 66 81 87 90

6 7 8 9

Note : Here the output is the inorder traversal of the BST.
 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.