CS 240: Algorithms and Data Structures
James Madison University, Fall 2021

Tracing Linked List Code

As a reminder, here is the Link Class from the reading:

Here is part of the LList class:

Using this code, complete the following diagramming and code-tracing exercises. Do not erase any values or links. Just cross them out.

  1. Draw a linked diagram of a freshly constructed list. Mark head, tail, and curr.
  2. Draw a linked diagram of a list containing the strings "A", "B", and "C" and which is currently positioned at "B". What happens when remove is called? Update the diagram as you trace through the method’s code. Do not erase any values or links. Just cross them out.
  3. Draw a linked diagram of a list containing the strings "A", "B", "C", and "D". and which is currently positioned at "C". What happens when list.precedes("D") is called? Update the diagram as you trace through the method’s code.


Analyzing List Algorithms

Analyze each of the methods below according to the instructions in the Javadoc comments.