CS 314 - Specification 5 - Linked Lists

Programming Assignment 5:  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 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 to set up so more chances for logic errors. But, it makes a lot of things easier because it is possible to move backwards in the linked structure of nodes without having to start over at the beginning, use the look ahead technique, or use a trailer node.

Files:

  File Responsibility
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. This class has the DoubleListNode.java class nested inside it. 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.
Optional Visual Tester LinkedListView.java A tool [its use is optional] created by one of our TAs [Andrew] for viewing the LinkedList. Download the class and refer to the documentation on the GitHub page. Provided by me (Okay, TA Andrew)
Documentation Javadoc files for DoubleListNode and IList.  

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 determine (guess?) what must be done or why something does not work. Don't program by permutation or try cargo cult programming.

Please realize, when you get an error in a test the cause is typically in another method. It is often the case that students make errors when adding or removing elements or changing the structure of the internal storage container (the linked structure of nodes), but the error does not manifest itself until later on in a test of toString.

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. In your final submission delete the provided tests. Add at least 2 tests of your own per method in the LinkedList class to the LinkedListTester class. Delete the provided tests. You may post the tests you write to the class class discussion group, but in the end you must implement your own tests.

 Note, most of my tests rely on your iterator method. If that is not working you will fail those 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, 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).  Implement the hasNext and next methods for your iterator. You shall replace the default remove method from the Iterator interface with a remove method that actually removes the last element returned by next. Your iterator class does NOT need to detect co-modification errors.

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.

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. To run the method simply uncomment the line at the end of the main method in LinkedListTester that calls the comparison method. You are free to change the initial value of N for the various tests in the comparison method.

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.  (Realize the experiments use different starting values of N.)

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.


Submission: Fill in the header in the LinkedListTester.java and LinkedList.java files.. Replace <NAME> with your name. Note, you are stating, on your honor, that you did the assignment on your own.

Create a zip file name a5.zip with your LinkedListTester.java and LinkedList.java files. The zip file must not contain any directory structure, just the required files.

See this page for instructions on how to create a zip via Eclipse.

Turn in a5.zip via your Canvas account to programming assignment 5.


Checklist. Did you remember to:


  Back to the CS 314 homepage.