Inserting a new node

When we are inserting a new node in the binary search tree, we have to consider the following steps:

  1. Create a new node as a leaf (no left child or right child).
  2. Start with the root node and set it as the current node.
  3. If the node is empty, make the new node as the root.
  4. Check whether the new value is less than the current node or more.
  5. If less, go to the left and set the left as the current node.
  6. If more, go to the right and set the right as the current node.
  7. Continue to step 3 until all the nodes are visited and the new node is set.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset