CMPS 101 Assignment 2: C Program for Shuffling Lists with Double Ended Queue ADT, Assignments of Computer Science

A programming assignment for cmps 101 students during summer 2006. The objective is to create a c program called 'shuffle' that shuffles lists of integers, ensuring students are familiar with c pointers and structures, modularity, and abstract data types (adts). Students must implement a double ended queue adt and write functions for constructors, destructors, access, manipulation, and other operations. The program will be structured in three files: shuffle.c, list.c, and list.h. Students must also submit a makefile, listclient.c, and a readme file.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-j8q
koofers-user-j8q 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPS 101
Algorithms and Abstract Data Types
Summer 2006
Programming Assignment 2
Due Thursday July 13, 10:00 pm
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);
pf3

Partial preview of the text

Download CMPS 101 Assignment 2: C Program for Shuffling Lists with Double Ended Queue ADT and more Assignments Computer Science in PDF only on Docsity!

CMPS 101

Algorithms and Abstract Data Types Summer 2006

Programming Assignment 2

Due Thursday July 13, 10:00 pm

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 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. Please note that the above file names are not optional. Your Makefile must create an executable called Shuffle and must include a clean facility 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:

Makefile for Programming Assignment 2

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 -f Shuffle.exe 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

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