You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution
public static Node insert(Node root,int data) { Node newNode = new Node(data); if (root == null) { return newNode; } Node current = root; root = current; while (true) { if (data > current.data) { if (current.right == null) { current.right = newNode; return root; } else { current = current.right; } } else if (data < current.data) { if (current.left == null) { current.left = newNode; return root; } else { current = current.left; } } } }
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 →
My Java 8 Solution