You are viewing a single comment's thread. Return to all comments →
if(root == null) return new Node(data); Node toInsert = new Node(data), temp = root; while(true) { if(toInsert.data <= temp.data) { if(temp.left != null) temp = temp.left; else { temp.left = toInsert; break; } } else if(toInsert.data > temp.data) { if(temp.right != null) temp = temp.right; else { temp.right = toInsert; 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 →