public class LinkedList { Node head; public void insert(int key) { Node current = head; while(current != null) { current = current.link; } } }Now let's extend the code to stop when we have found the spot to insert the new element. For example, if we are inserting a 15 into the following list, it must go between 11 and 18.
What condition will be true until we reach the stopping node -- the node before which the new one must be inserted? (The condition will become false when we do reach the stopping node, causing the loop to stop.)
How should we join the two conditions?
(Remember that && means "and" in Java, and || means "or".
Now we can stop in the following situation. (Again, assume that we are inserting 15.)
To move on to the next step, click here.