CSC300 / CSC402: The End [4/6] Previous pageContentsNext page

Now figure out what to do if you hit null.

11
12
13
14
15
16
17
18
19
20
  public void insert (double item) {
    Node x = first;
    while (x.next != null && x.next.item < item) {
      x = x.next;
    }
    Node y = new Node (item, null);
    Node f = x.next;
    x.next = y;
    y.next = f;
  }

Passes more tests

Previous pageContentsNext page