CPSC 211, Sec 201-203
Spring 2004
Program 1: Implementing a Set ADT with a Linked List in Java
INSTRUCTIONS
PURPOSE
This assignment is intended for you to get back in practice with
Java and to learn (or review) how to program a basic linked list.
It also is a simple of example of using data abstraction.
PROGRAM REQUIREMENTS
Write a Java class DLList in which the data is a list of entities,
each of type Object.
It must have the following instance methods:
- insertFront(o) - insert a new node containing object o at the
front of the list
- insertBack(o) - insert a new node containing object o at the
back of the list
- insertAfter(o1,o2) - insert a new node containing object o1
immediately after the node containing the object o2 (you
figure out what to do if o2 does not appear in the list or
appears multiple times).
- deleteFront - delete the node at the front of the list and
return the object that it contained
- deleteBack - delete the node at the back of the list and
return the object that it contained
- delete(o) - delete the node that contains the object o
- isEmpty - returns true if the list is empty and false otherwise
Write a Java class Set in which the data is a collection of
entities, each of type Object.
It must have the following instance methods:
- insert(o) - insert object o into the set
- isIn(o) - returns true if o is in the set and false otherwise
- delete(o) - deletes the object o from the set
- isEmpty - returns true if the set is empty and false otherwise
- union(T) - T is another set; when this method is called for set S,
the result is to add all the elements in T to S.
It is your choice what happens to T, but be sure to document it!
- intersect(T) - T is another set; when this method is called for
set S, the result is to remove from S every element that is not
also in T.
It is your choice what happens to T, but be sure to document it!
IMPLEMENTATION REQUIREMENTS
- Implement the class DLList with a doubly-linked list.
- Implement the class Set with a DLList object. Be sure to use
information hiding.
- Be sure your program runs on the CS department's Unix machines
when compiled with JDK!
TURN-IN REQUIREMENTS
Due by 10:20 AM on Wednesday, Feb 4:
- Turn in your code using the "turnin" program in the CS department
Unix machines.
(Turnin instructions available here.)
- Turn in the paper testing documentation and cover sheet.