

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


To perform a perfect shuffle you should split your deck into two other decks by alternately “dealing” from
the top and bottom of the original deck, and inserting the cards into the new decks, then combine these
two decks by alternately “dealing” off their bottoms.
Your List ADT will actually be a double ended queue with a current-position marker. Thus the set of “mathematical structures” for this ADT consists of all finite sequences of integers, where one integer may (or may not) be distinguished as the current element. This current element will be used by the client (namely your Shuffle program) to traverse the lists. Your List module will support the following operations:
// Constructors List() // Creates an empty list
// Access functions boolean isEmpty() // Returns true if list contains no elements. boolean atFirst() // Returns true if current marker refers to first element. boolean atLast() // Returns true if current marker refers to last element. boolean offEnd() // Returns true if no element is current. int getFirst() // Returns first element in list. Pre: !isEmpty(). int getLast() // Returns last element in list. Pre: !isEmpty(). int getCurrent() // Returns current element in list. Pre: !isEmpty(), !offEnd(). int getLength() // Returns length of list. boolean equals(List L) // Returns true if this list contains same elements // as argument list.
// Manipulation Procedures void moveFirst() // Makes first element current. Pre: !isEmpty(), Post: !offEnd(). void moveLast() // Makes last element current. Pre: !isEmpty(), Post: !offEnd(). void moveNext() // Steps the current marker toward end of list. // Pre: !isEmpty(), !offEnd(). void movePrev() // Steps the current marker toward beginning of list. // Pre: !isEmpty(), !offEnd(). void insertBeforeFirst(int data) // Adds new element to beginning of list. // Post: !isEmpty(). void insertAfterLast(int data) // Adds new element to end of list. // Post: !isEmpty(). void insertBeforeCurrent(int data) // Inserts new element just before current. // Pre: !isEmpty(), !offEnd(). void insertAfterCurrent(int data) // Inserts new element just after current. // Pre: !isEmpty(), !offEnd(). void deleteFirst() // Deletes first element. Pre: !isEmpty(). void deleteLast() // Deletes last element. Pre: !isEmpty(). void deleteCurrent() // Deletes current element. // Pre: !isEmpty(), !offEnd(); Post: offEnd().
// Other Operations List copy() // Returns a new List containing the same elements as this list. public String toString() // Overrides Object's toString method. public static void main(String[] args) // Test driver for the List class.