CS 239 - More fun with implementing data structures


Prepping for the final

Java supports data structures with a number of classes.  The Collections framework is an interface that enforces similar tasks across all classes which purport to be a Collection.


Examples: ArrayList implements Collection.  (Along with a bunch of other interfaces).

Other classes of interest:
Queue - This is an interface, not a structure.  Example
Stack - Is a class.  Implements Collection and extends Vector.
HashTable - Is a class.  It does not implement Collection.  (Didn't this make the color search problem much easier?)
Set - Is an interface.  Does not permit duplicate elements.  extends Collection.

At this point, you just need to be familiar with Stacks and Queues and some basic operations of data structures.  You will get into much more next semester.

 In your groups, write the code to implement two methods in an OrderedList class.  The OrderedList class is a linked list that is maintained in sorted order.  Each node contains a rank (any positive integer) and a value (an object) along with a link to the next node object.  

When you add a node, you must put it in order.  Consider carefully the different situations (empty list, adding to beginning, middle, and end.)

When you take a node, you must be careful that you don't lose your list.  How will you hang onto the pieces.

Post your algorithms on the board when done.