The algorithm for identifying a node's correct location is as follows: 1. Make the current node, which is the root node, the parent node. 2. If the data value in the new node is smaller than the data value in the existing node, make the current node the current node's left child. Skip to Step 4 if the data value in the new node is larger than the data value in the existing node. 3. If the value of the current node's left child is null, place the new node here and leave the loop. Otherwise, go to the next While loop iteration. 4. Set the current node to the right child node of the current node. 5. If the value of the right child of the current node is null, insert the new node here and exit the loop. Otherwise, skip to the next iteration of the While loop Write The code for the Insert method, along with the rest of the code for the BST class.
The
1. Make the current node, which is the root node, the parent node.
2. If the data value in the new node is smaller than the data value in the existing node, make the current node the current node's left child. Skip to Step 4 if the data value in the new node is larger than the data value in the existing node.
3. If the value of the current node's left child is null, place the new node here and leave the loop. Otherwise, go to the next While loop iteration.
4. Set the current node to the right child node of the current node.
5. If the value of the right child of the current node is null, insert the new node here and exit the loop. Otherwise, skip to the next iteration of the While loop
Write The code for the Insert method, along with the rest of the code for the BST class.
Step by step
Solved in 3 steps