CS 307Assignment, Linked Lists

Programming Assignment 8: This is an individual assignment. You must complete this assignment on your own. You may not discuss their work with anyone except the instructor and other members of the instructional staff (TA, section leader, or lab proctor). You may not acquire, from any source (e.g., another student or an internet site), a partial or complete solution to a problem or project that has been assigned. You may not show another student your solution to an assignment. You may not have another person (current student, former student, tutor, friend, anyone) “walk you through” how to solve an assignment. Review the class policy on collaboration from the syllabus.

Placed online: Friday, July 30
20 points, ~2% of total grade
Due: no later than 11 pm, Monday, August  9
General Assignment Requirements

Description:  The purposes of this assignment are to:

  1. implement an abstract data type using Java's generic syntax.
  2. work with linked data structures
  3. implement an iterator

In this assignment you will be implemented a linked list that uses doubly linked nodes. In class most of our examples were a list with singly linked nodes. Doubly linked nodes have references (pointers) to the next node in the list and back to the previous node in the list. This makes some things harder because there are more references (pointers) to set up. But, it makes a lot of things easier because now it is possible to back up in the list without having to start over at the beginning, use the look ahead technique, or use a trailer node.

Provided Files:

  File Responsibility
Source Code DoubleListNode.java (Alternatively you can add a nested class to the LinkedList class for the doubly linked nodes as demonstrated in lecture. None of the test cases will reference the DoubleListNode class.) Provided by me.
Source Code IList.java Provided by me. Do not alter
Source Code Stopwatch.java Provided by me. Do not alter.
Implementation LinkedList.java. Implementation of a doubly linked list. Provided by you and me.  (Okay, mostly you.)
Test code LinkedListTester.java. Test harness. correct any tests that have errors. Ensure your LinkedList class passes the tests included and add many more tests. Provided by you and me.
Documentation Javadoc files for DoubleListNode, IList, and LinkedList  

DoubleListNode provides code for a doubly linked list node. (Alternatively you can add a nested class to the LinkedList class for the doubly linked nodes as demonstrated in lecture. None of the test cases will reference the DoubleListNode class.)

IList provides the interface for for a List abstract data type. Do not alter this interface.

LinkedList implements the IList interface. Complete this class under the restrictions of the general assignment requirements. For this assignment you may not use the LinkedList or ArrayList classes from the Java standard library. You must implement the underlying storage container as a doubly linked structure using the DoubleListNode class. The DoubleListNodes and LinkedList are generic based on Java's generic syntax.

LinkedListTester provides some tests for the LinkedList class. Some of these tests may be incorrect. Find and fix any incorrect tests. Your class must pass these (corrected) tests. Add at least 3 tests of your own per method in the LinkedList class to the LinkedListTester class. Use the class listserv to discuss which tests are in error and how to correct. Post the tests you write to the class listserv. Note, most of my tests rely on your iterator method. If that is not working you will fail the tests. I strongly recommend you test your methods as you complete them by writing your own tests! Write a method, then test it. Write a method, then test it. DON'T do this:  write a method, write a method, write a method, ... then test ...then debug, debug, debug, debug, debug, debug.

Implementation details: In this assignment you will implement a list class using a doubly linked structure as the internal storage container. You may approach the implementation in many ways. (References to first and last node, circular list with only a link to the first node, use of dummy nodes or not.) The approach you take is up to you. Each has certain advantages and disadvantages.

In addition to implementing the methods specified in the IList interface you must add  the following methods to the LinkedList class. E is the data type variable. It will hold what the data type is for the elements (thus the E) of a particular LinkedList object.

For each and every method in the LinkedList class state the Big O of the method if there are already N items in the list.

You can, of course, implement methods in using of other methods from the class. You should only do this if the version of a method that relies on other methods in the class is as efficient as not using other methods.

Experiments: It is interesting and important to know the difference in behavior between linked lists and array based lists. When your LinkedList class is finished, run the comparison method from the LinkedListTester class which performs a number of tests between your LinkedList and the Java ArrayList class. In a comment at the top of your LinkedListTester class indicate which operations are faster when using your LinkedList, which are faster when using the Java ArrayList class, and which ones are about the same regardless of which list is used.

When finished turn in your LinkedList.java and LinkedListTester.java classes using the turnin program. (No jar this time.)

Checklist:  Did you remember to:

Tips: Draw pictures!! When completing methods and figuring out all the references that have to be updated and what the special cases are DRAW PICTURES of the linked structure. This is much easier than just looking at code and trying to figure out what must be done or why something does not work.

The Iterator. The IList interface calls for a method named iterator. This method returns an object of type Iterator that can be used to traverse efficiently through the elements of the list in order. Without the iterator the only way to traverse the list is via N calls to get and that would have a Big O of N2, (N calls to get, an efficient get does an average of N/4 steps per call to get the specified item). In order to implement the iterator and not make the data members of the LinkedList class public you will make it an inner class. Inner classes are defined as follows:

public class LinkedList<E> implements IList<E>{
    //code for LinkedList class

    private class LLIterator implements Iterator<E>{
        // There is no <E> after LLIterator because E is already
        // defined in the outer class, LinkedList

        //code for the LLIterator class


Inside the LLIterator class you must define all the methods from the Iterator interface. As an inner class, LLIterator will have access to the private data members of the LinkedList class. For this assignment you must implement a working version of the remove method from the Iterator interface.

If you wish to use the remove method from the LinkedList class in the Iterator remove method, there is a conflict with naming. You have to use the following syntax.

//in LLIterator's remove method
LinkedList.this.remove( blah );

Realize you can and should implement the iterator remove method much more efficiently, O(1), than the LinkedList's remove method. It is also simpler to implement the iterator remove method with doubly linked nodes than it was with singly linked nodes.

  Back to the CS 307 homepage.