Insert a node in a BST
Submissions: 15949   Accuracy:


  Difficulty: Easy

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.

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 . 

1 <= T <= 100
1 <= N <= 100


2 81 87 42 66 90 45 
6 7 9 8

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
Author: Shubham Joshi 1

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