Quiz 13 (Exercise for Chap. 19: Linked List and iterator)

The objective of these questions is to test your ability to use the Link class. So, you cannot use the LinkedList class, or a stack or an array, just the Link class. Recall that the Link class has public instance variables Object data, Link next and a constructor Link(Object, Link) for setting these instance variables.
  1. Write a method

    public static Link reverse(Link first)

    which receives a reference to the first element of a chain of Link objects and returns a reference to the last one with the chain now reversed. That is, if the input chain is ABCDE, and first points to A, the returned reference is to E, and the chain is EDCBA.
  2. Write a method

    public static Link cutSeconds(Link first)

    which receives a reference to the first element of a chain of Link objects and returns a reference to the second one (if there is a second one) and the new chain is missing the first, third, etc. elements of the old chain. That is, if the input chain is ABCDE, and first points to A, the returned reference is to B, and the chain is BD, since the A, C and E were removed.