You are viewing a single comment's thread. Return to all comments →
Java:
public static Node insert(Node root,int data) { Node n = new Node(data); Node head = root; if (root == null) { root = n; } while (head != null) { if (data < head.data && head.left == null) { head.left = n; break; } else if (data < head.data && head.left != null) { head = head.left; } else if (data >= head.data && head.right != null) { head = head.right; } else if (data >= head.data && head.right == null) { head.right = n; break; } } return root; }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all comments →
Java: