CS 314 - Specification 6 - Linked Lists

Programming Assignment 6:  Individual Assignment. You must complete this assignment on your own. You may not acquire from any source (e.g.  another student or a web 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. You may get help from the instructional staff. You may discuss general ideas and approaches with other students but you may not develop code together. Review the class policy on collaboration from the syllabus.

The purpose of this assignment is to implement a linked list class that uses doubly 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 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.

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 reference the DoubleListNode class.) Provided by me. Do not alter.
Source Code IList.java Interface your LinkedList class implements. 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 more tests. Provided by you and me.
Documentation Javadoc files for DoubleListNode, IList, and LinkedList  

Implementation details:

Complete the LinkedList class.  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.

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 header nodes that don't contain any data) 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.

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. In your final submission delete the provided tests. Add at least 3 tests of your own per method in the LinkedList class to the LinkedListTester class. Use the class discussion group to discuss which tests are in error and how to correct. Post the tests you write to the class class discussion group. 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, debug, debug, debug.

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

The methods for the iterator for your linked list shall all be O(1).

If a method has preconditions you must check those preconditions and throw an Exception if they are not met.

You can, of course, implement methods using 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.

As always, use good style: comments for non obvious algorithms and operations, good variable names, use helper methods if necessary, make operations as efficient as possible given the constraints.

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.

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 with 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. Note, the experiments only do one test for a given number of elements (N) and some of the timing results may be unexpected. Change the test to run multiple tests (on the order of 100 or more) with the same number of elements multiple times and take an average.

For the operations tested via the experiment what do you think the Big O of each operation / method is based on the timing data? State your reasoning.

When finished turn in your LinkedList.java and LinkedListTester.java classes using the turnin program.


Checklist:  Did you remember to:


  Back to the CS 314 homepage.