CS 51 Homework Laboratory # 12
Circular Doubly-Linked List

Objective: To gain experience with linked lists.

In this lab, I'd like you to complete the implementation of a circular doubly-linked list. The only differences between this and the doubly-linked list covered in class are that
  1. the next field of the last node refers to the first node in the list.
  2. the previous field of the first node refers to the last node in the list.
  3. there is no instance variable referring to the end of the list. Instead you can get from the head to the last element by following the previous link of the head node.

Not having to keep track of both the head and tail of the list will simplify much of the code. In particular removeLast and addLast no longer must update the tail instance variable.

For this assignment I have provided a starter that includes most of the methods. You need only write the following methods of class CircularDoublyLinkedList:

  1. removeFirst(),
  2. addLast(),
  3. get(i), and
  4. add(i, value).

You will find that if you think about it you can write removeFirst by using the already provided method removeLast and one more line of code. Similarly, addLast can use the method addFirst. (Do not copy the code in these methods, call them directly in your method bodies. If you do write these properly, each of these two methods requires only 2 lines of code.)

The last two will be more complex. However, their bodies share some similarities with the code provided in set(i,newValue).

The program TestLinkedList will pop up a window that illustrates snapshots of the list at certain points. In the text area below is printed other information, including descriptions of the graphics of the lists that should help you see if your code works.

Submitting Your Work

When your work is complete you should deposit in the dropoff folder a copy of your folder. Before you do this, make sure the folder name includes the phrase "Lab 12" and your name. Also make sure to double check your work for correctness, organization and style. This assignment is due Thursday evening, though you will likely be able to finish it during the lab and then go on to work on your test program.

Grading Point Allocations

Value
Feature
Syntax Style (3 pts total)
1 pt. Descriptive comments
1/2 pt. Good names
1 pt. Good use of constants
1/2 pt. Appropriate formatting
Code quality (3 pts total)
1 pt. conditionals and loops
1 pt. General correctness/design/efficiency issues
1 pts. Parameters, variables, and scoping
Correctness (4 pts total)
1 pt. removeFirst
1 pt. addLast
1 pt. get(i)
1 pt. add(i,value)


Computer Science 051
Department of Math & Computer Science
Pomona College