Home Assignments Quizes

Project 2: Doubly-Linked Lists

Due Date: Thu, May 22th (extended)

Lists are vital in computer science and are used frequently in programming. Because of this, it is important that you fully understand how lists work. In this project, you will implement a doubly-linked list.

Goals of the Project

The primary goals of the project are to:

What to Do

You will need at least one interfaces and two classes to build this project with the following names:

Iterator<Item> has the following methods:

Note that you will need to create a concrete version of this Iterator class from DLList that can walk through the DLList. This is done by creating a private, inner class inside DLList and returning it through the call from iterator().

List<Item> extends java.util.Iterable<Item>. List has the following methods:



DLList<Item> implements List<Item>. You must therefore define all the methods in the List<Item> interface as specified above. Note that the List<Item> interface is slightly different than Java's, so you have to create it yourself.

Things to Note

You may not use Java's LinkedList class in any way in this project. You must name your classes with the given names. Your Doubly-Linked List class must be called DLList. We will be creating a main method in a testing class that will expect these names. If you do not use these names correctly, you will loose points!

If the user performs any illegal operation (for example, more than one call to remove) then you must throw an exception.

Your specific Iterator class and the Node class should most likely be internal classes for DLList. Internal classes are accessible by the parent class and are defined just like regular classes, but inside another class. Note that List<Item> must extend Iterable<Item> so that you can use Java's foreach call.

Turn-in

You will need to use subversion with your group or solo (remember, groups can be up to 3 people). We will simply check-out your repository at the end of the day that the project is due, so check-in your project frequently and of course when you're done.

You must include comments in your code to explain what you're doing. In your comments, you need to state what the expected running time, in terms of n, will be to call that method.

Grading

Your project will be graded on the correctness of your implementation and your understanding of its performance. In particular:

Extra Credit

For extra credit, add the following two methods to the Iterator class:

Note that if you remove an item, it must be the item you just returned from previous or next. If you add an item, it will be returned by a subsequent call to previous.