

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 students during summer 2009. The objective is to create a c program with the same functionality as a previous assignment, focusing on c programming, modularity, and abstract data types (adts). Students must write a program called 'shuffle' that shuffles lists of integers, using a list adt as a double ended queue. Instructions on file input and output, constructors, destructors, access functions, manipulation procedures, and other operations. Students must also structure their program into three files: a client program, a list implementation file, and a list header file. They must also turn in additional files for testing and documentation.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Algorithms and Abstract Data Types Summer 2009
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 in future assignments. Again you are to write a program that shuffles lists of integers. Your executable will be called Shuffle and will be invoked at the command line by typing: Shuffle in_file out_file. The program FileIO.c on the class webpage shows how file input and output can be accomplished in C. The program operation and file formats for this project will be identical to that described in pa1. 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”. Your List module will export a ListRef type, along with the following operations. /*** Constructors-Destructors / ListRef newList(void); void freeList(ListRef pL); /* Access functions / int isEmpty(ListRef L); int offEnd(ListRef L); int atFirst(ListRef L); int atLast(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 makeEmpty(ListRef L); 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 **/ void printList(FILE out, ListRef L);
ListRef copyList(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 the List L to the file pointed to by out, formated as a space-separated string. This function plays roughly the same role as the “toString” function in Java. The operation of the other functions, and they’re preconditions, are described in the pa1 specifications. Note that the int type in C will stand in for boolean in java, with 1 being true and 0 false. 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 pa1. ListRef catList(ListRef A, ListRef B); Your program will 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 ListTest.c whose purpose is to test your List module in isolation, and a README file describing the files created for this assignment, their purposes, and relationships. Please note that the above file names are not optional. Your Makefile must create an executable called Shuffle and must include a clean utility that removes all executables and object files. Each file you turn in must begin with your name, user id, and assignment name. Thus for this project, you will turn in 6 files altogether. 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 ListTest: List.o ListTest.o gcc -o ListTest ListTest.o List.o ListTest.o : List.h ListTest.c gcc -c -ansi -Wall ListTest.c List.o : List.h List.c gcc -c -ansi -Wall List.c clean : rm -f Shuffle ListTest Shuffle.o ListTest.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 Target : Dependencies Operation separated by blank lines. Important note: the white space before the “operation” is a tab, not spaces! Target is a file to be created, and the dependency list for that target consists of those files on which the target depends. If one of the files in the dependency list changes, the target will be recompiled. Operation is the command which creates the target. The targets are listed in “top down” order, since