Project: Doubly-Linked List Implementation of List with Retreat
Objectives
- Familiarity with writing a kernel class for a new type and its
kernel operations (
Listwith the extraretreatmethod) using references (also known as pointers) to build a doubly-linked list of nodes. - Familiarity with developing and using specification-based test plans.
The Problem
The problem is to complete and carefully test implementations of the
constructor and all kernel methods defined in interface ListKernel
plus the methods retreat and moveToFinish defined in interface
List, by building a representation that involves a doubly-linked list
of nodes using Java references.
The retreat method gives the client the ability to move backward one
position at a time. The ListKernel allows only incremental forward
movement; moving backward is possible only by "jumping" all the way back
to the start using moveToStart. Method retreat is just the inverse
of advance.
Note that retreat (and moveToFinish) can be implemented by layering,
i.e., by using only the ListKernel methods and, indeed, such
implementations exist in the ListSecondary class. You should know
how to write that code! However, the execution time of the layered
implementations is linear in the length of the left string of the list
(for retreat or of the right string of the list for moveToFinish).
The challenge here is to implement ListKernel and retreat and
moveToFinish so all the methods take constant time, independent of the
sizes of the left and right strings of the list. This is possible only
by implementing all the methods directly, i.e., not by layering on an
existing implementation of ListKernel but by creating an entirely new
implementation that is based on a doubly-linked list data structure.
Setup
Only one member of the team should follow the steps to set up an Eclipse project for this assignment. The project should then be shared with the rest of the team by using the Subversion version control system as learned in the Version Control With Subversion lab.
To get started, import the project for this assignment,
ListWithRetreat, from the ListWithRetreat.zip file available at this
link. If you don't remember how to do this, see
these Setup
instructions
from an earlier project.
Method
- Complete the bodies of the private method
createNewRep, the constructor, the kernel methods (addRightFront,removeRightFront,advance,moveToStart,leftLength, andrightLength), and themoveToFinishandretreatmethods inList3in thesrcfolder. - Review the test plan for the
ListKernelconstructor, kernel methods, and iterator provided inListTestin thetestfolder. At the end ofListTest.java, add appropriate test cases (consistent with the given plan) for theretreatmethod. Test yourList3implementation. Important Note: Even if your implementation passes all the given test cases, it does not mean it is correct! Testing is not a substitute for carefully and thoughtfully reviewing your code to convince yourself that it is correct through reasoning. - When you and your teammate(s) are done with the project, decide who
is going to submit your solution. That team member should select the
Eclipse project
ListWithRetreat(not just some of the files, but the whole project) containing the complete group submission, create a zip archive of it, and submit the zip archive to the Carmen dropbox for this project, as described in Submitting a Project. Note that you will only be allowed one submission per group, that is, your group can submit as many times as you want, but only the last submission will be on Carmen and will be graded. Under no circumstance will teammates be allowed to submit separate solutions. Make sure that you and your partner agree on what should be submitted.
Additional Activities
Here are some possible additional activities related to this project. Any extra work is strictly optional, for your own benefit, and will not directly affect your grade.
- Design test cases—and add them to
TestList.java—to test the methods from theStandardinterface (newInstance,clear, andtransferFrom). - Create a new implementation of
ListKernelwithretreat(call itList3a) that does not use the two "smart nodes" in the doubly-linked list representation. Then explain the purpose of these nodes and why they deserve to be called "smart nodes" rather than the traditional "dummy nodes". - Create a main program from scratch, so you can estimate the
execution times for the various
List3methods.