

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming assignment for cmps 101 summer 2005, where students are required to write a c program that performs a perfect shuffle on a given positive integer using a double ended queue adt. Instructions on the functionality of the program, required handouts, and the structure of the files. Students will practice c programming, modularity, and adts.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Algorithms and Abstract Data Types Summer 2005
In this assignment you will create a program with the same functionality as pa1 , but now in C. Our purpose is again threefold: to make sure everyone is up to speed with C (especially pointers and structures), to practice modularity and ADTs, and to build an ADT implementation which will be used (with modifications) in future assignments. Again you are to write a program that takes as input a single positive integer n from the command line, and performs a perfect shuffle on n cards (in order) until the original sorted order is reproduced, then print out the number of shuffles performed. The program operation will be as described in the pa1 handout. As before your List ADT will be a double ended queue, with a current-position marker. Read the handout entitled “ADTs and Modules in Java and ANSI C”, paying special attention to the section on ANSI C. Also read the handout entitled “Some Additional Remarks on ADTs and Modules in ANSI C”. Both handouts are posted on the webpage. Your List module will export a ListRef type, and support the following operations. /***** Constructors-Destructors *****/ ListRef newList(void); void freeList(ListRef* pL); /***** Access functions *************/ int isEmpty(ListRef L); int atFirst(ListRef L); int atLast(ListRef L); int offEnd(ListRef L); int getFirst(ListRef L); int getLast(ListRef L); int getCurrent(ListRef L); int getLength(ListRef L); int equals(ListRef A, ListRef B); /***** Manipulation procedures ******/ void moveFirst(ListRef L); void moveLast(ListRef L); void movePrev(ListRef L); void moveNext(ListRef L); void insertBeforeFirst(ListRef L, int data); void insertAfterLast(ListRef L, int data); void insertBeforeCurrent(ListRef L, int data); void insertAfterCurrent(ListRef L, int data); void deleteFirst(ListRef L); void deleteLast(ListRef L); void deleteCurrent(ListRef L); /***** Other operations **********/ ListRef copy(ListRef L); void printList(ListRef L);
Function newList returns a ListRef which points to a new empty list. Function freeList frees all heap memory associated with its ListRef* argument, and sets *pL to NULL. Function printList() prints out the current state of a List object. This function plays roughly the same role as the “toString” function in Java, and will be invaluable when debugging your list module. The other functions are described in the pa1 specifications. You may also wish define a type called ListElement, which is just a synonym for int. ListElement would then be the return type of several access functions, and input parameter type for several manipulation procedures, making it easy to recast your integer List as a “list- of-something-else” if necessary. All of the above functions are required for full credit, but you may add additional operations if you like such as the following, whose operation is described in pa. ListRef cat(ListRef A, ListRef B); void makeEmpty(ListRef L); Your program should be structured in three files: a client program (Shuffle.c), a List implementation file (List.c), and a List header file (List.h). You must also turn in three other files: a Makefile, a driver program (ListClient.c) whose purpose is to test your List module (i.e. taking the place of function main in the Java List class), and a README file describing the files created for this assignment, their purposes, and relationships. Note that the above file names are not optional. In addition, your Makefile must create an executable called Shuffle for proper grading. Each file you turn in must begin with your name, and cats user ID. A simple Makefile for this assignment might look like:
Shuffle : List.o Shuffle.o gcc -o Shuffle Shuffle.o List.o Shuffle.o : List.h Shuffle.c gcc -c -ansi -Wall Shuffle.c ListClient: List.o ListClient.o gcc -o ListClient ListClient.o List.o ListClient.o : List.h ListClient.c gcc -c -ansi -Wall ListClient.c List.o : List.h List.c gcc -c -ansi -Wall List.c clean : rm Shuffle ListClient Shuffle.o ListClient.o List.o The first line is a comment, as are all lines starting with “#”. The rest of the file is organized into blocks of the form