@@ -0,0 +1,1656 @@
+// Java program to demonstrate insert operation in binary search tree%0Aclass BinarySearchTree %7B%0A%0A%09/* Class containing left and right child of current node and key value*/%0A%09class Node %7B%0A%09%09int key;%0A%09%09Node left, right;%0A%0A%09%09public Node(int item) %7B%0A%09%09%09key = item;%0A%09%09%09left = right = null;%0A%09%09%7D%0A%09%7D%0A%0A%09// Root of BST%0A%09Node root;%0A%0A%09// Constructor%0A%09BinarySearchTree() %7B %0A%09%09root = null; %0A%09%7D%0A%0A%09// This method mainly calls insertRec()%0A%09void insert(int key) %7B%0A%09%09root = insertRec(root, key);%0A%09%7D%0A%0A%09/* A recursive function to insert a new key in BST */%0A%09Node insertRec(Node root, int key) %7B%0A%0A%09%09/* If the tree is empty, return a new node */%0A%09%09if (root == null) %7B%0A%09%09%09root = new Node(key);%0A%09%09%09return root;%0A%09%09%7D%0A%0A%09%09/* Otherwise, recur down the tree */%0A%09%09if (key %3C root.key)%0A%09%09%09root.left = insertRec(root.left, key);%0A%09%09else if (key %3E root.key)%0A%09%09%09root.right = insertRec(root.right, key);%0A%0A%09%09/* return the (unchanged) node pointer */%0A%09%09return root;%0A%09%7D%0A%0A%09// This method mainly calls InorderRec()%0A%09void inorder()  %7B%0A%09%09inorderRec(root);%0A%09%7D%0A%0A%09// A utility function to do inorder traversal of BST%0A%09void inorderRec(Node root) %7B%0A%09%09if (root != null) %7B%0A%09%09%09inorderRec(root.left);%0A%09%09%09System.out.println(root.key);%0A%09%09%09inorderRec(root.right);%0A%09%09%7D%0A%09%7D%0A%0A%09// Driver Program to test above functions%0A%09public static void main(String%5B%5D args) %7B%0A%09%09BinarySearchTree tree = new BinarySearchTree();%0A%0A%09%09/* Let us create following BST%0A%09%09   50%0A%09%09   /     %5C%0A%09%09   30      70%0A%09%09   /  %5C    /  %5C%0A%09%09   20   40  60   80 */%0A%09%09tree.insert(50);%0A%09%09tree.insert(30);%0A%09%09tree.insert(20);%0A%09%09tree.insert(40);%0A%09%09tree.insert(70);%0A%09%09tree.insert(60);%0A%09%09tree.insert(80);%0A%0A%09%09// print inorder traversal of the BST%0A%09%09tree.inorder();%0A%09%7D%0A%7D%0A

Create BST.java