For your sixth lab, you will implement a doubly-linked list. Your
list should have both a head and a tail pointer, and should contain
dummy header and trailer elements, to avoid special cases for empty
lists, and inserting and removing from the front/end of the list.
Your linked list should have the following methods (in addition to a
constructor):
- public void insert(Object o)
Inserts o at the
beginning of the list.
- public void insertAt(Object
o, int index) Inserts o at index index. If index is greater than the size
of the list, insert o at
the end of the list
- public boolean find(Object
o) Returns true if and only if o is in the list (using
.equals)
- public void removeAt(int
index) Removes the element at index index. If index is
outside the bounds of the list, do nothing
- public void remove(Object o)
Removes the first occurence of o
from the list. If o
is not in the list, do nothing.
- public void append(Object o)
Append o to the end of
the list
- public String toString()
Create a string representation of the list, which consists of a left
parenthesis "(", followed by the result of calling toString() on each
element in the list (separated by ,'s -- don't forget the fencepost
problem!), followed by ")".
- public int size()
Returns the number of elements in the list
- public void reverse()
Reverses the list. There is an easy way to do this and (many!)
hard ways. Since the list is doubly-linked, you should be able to
do reversing by swapping some pointer values ...
Your class should also contain a public static void main(String args[])
that thoughoughly tests all of your methods
Grading
- Commenting / following conventions / etc 10 points
- Constructor / Element class 10 points
- insert 5 points
- insertAt 5 points
- find 5 points
- removeAt 5 points
- remove 5 points
- append 5 points
- toString 10 points
- size 10 points
- reverse 20 points
- main (for testing) 10 points
Submission
All file(s) required for
your project should be in the folder
https://www.cs.usfca.edu/svn/<username>/cs112/Lab7/