CSC300: Insertion logic [3/7] Previous pageContentsNext page

To create this, you work in pieces: first get the insert logic.

11
12
13
14
15
16
17
18
  public void insert (double item) {
    Node x = first.next;

    Node y = new Node (item, null);
    Node f = x.next;
    x.next = y;
    y.next = f;
  }

Passes some tests (inserts the item after first, as long as list is not empty)

Now figure out the loop.

As with all loops we work in pieces:

Previous pageContentsNext page