CMPSCI 187: Programming With Data Structures

Solutions to Second Midterm Exam

David Mix Barrington and Mark Corner

30 October 2014

Directions:

Question text is in black, solutions in blue.

  Q1: 24 points
  Q2: 20 points
  Q3: 20 points
  Q4: 16 points
  Q5: 20 points
Total: 100 points

Questions 2 and 5 refer to the following class whose objects are nodes in a linked list -- this is the same class used on the first midterm:

public class LLNode<T> {
   private LLNode<T> next;
   private T contents;

   public LLNode (T x)
      {contents = x; next = null;}

   public void setContents (T x) {contents = x;}
   public T getContents( ) {return contents;}
   public void setNext (LLNode<T> t) {next = t;}
   public LLNode<T> getNext( ) {return next;}
}