You are viewing a single comment's thread. Return to all comments →
thank you for you share, you can solve it that code below, it can save some code (my code is written by Java).
There is not need variable rs and ls
rs
ls
static Node Insert(Node root, int value) { Node newNode = new Node(); newNode.data = value; if (root == null) { return newNode; } Node iterator = root; while (iterator != null) { if (value < iterator.data) { if (iterator.left == null) { iterator.left = newNode; break; } iterator = iterator.left; } else { if (iterator.right == null) { iterator.right = newNode; break; } iterator = iterator.right; } } 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 →
thank you for you share, you can solve it that code below, it can save some code (my code is written by Java).
There is not need variable
rs
andls