Abstract Data Types - Programming Assignment II | CMPS 101, Assignments of Computer Science

Material Type: Assignment; Class: Algorithms and Abstract Data Types; Subject: Computer Science; University: University of California-Santa Cruz; Term: Unknown 2000;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-4xp
koofers-user-4xp 🇺🇸

2

(1)

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPS 101
Abstract Data Types
Spring 2003
Programming Assignment 2
Due Friday April 18, 12:00 midnight
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 other 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 (originally 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. Some additional remarks on implementing ADTs in C are also posted on the webpage. Your
List module will export a ListHndl type, and support the following operations.
/***** Constructors-Destructors *****/
ListHndl NewList(void);
void FreeList(ListHndl* pL);
/***** Access functions *************/
boolean isEmpty(ListHndl L);
boolean atFirst(ListHndl L);
boolean atLast(ListHndl L);
boolean offEnd(ListHndl L);
int getFirst(ListHndl L);
int getLast(ListHndl L);
int getCurrent(ListHndl L);
int getLength(ListHndl L);
boolean equals(ListHndl A, ListHndl B);
/***** Manipulation procedures ******/
void moveFirst(ListHndl L);
void moveLast(ListHndl L);
void movePrev(ListHndl L);
void moveNext(ListHndl L);
void insertBeforeFirst(ListHndl L, int data);
void insertAfterLast(ListHndl L, int data);
void insertBeforeCurrent(ListHndl L, int data);
void insertAfterCurrent(ListHndl L, int data);
void deleteFirst(ListHndl L);
void deleteLast(ListHndl L);
void deleteCurrent(ListHndl L);
/***** Other operations **********/
ListHndl copy(ListHndl L);
void printList(ListHndl L);
pf3

Partial preview of the text

Download Abstract Data Types - Programming Assignment II | CMPS 101 and more Assignments Computer Science in PDF only on Docsity!

CMPS 101

Abstract Data Types

Spring 2003

Programming Assignment 2

Due Friday April 18, 12:00 midnight

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 other 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 (originally 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 pa

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. Some additional remarks on implementing ADTs in C are also posted on the webpage. Your

List module will export a ListHndl type, and support the following operations.

/***** Constructors-Destructors *****/ ListHndl NewList(void); void FreeList(ListHndl* pL); /***** Access functions *************/ boolean isEmpty(ListHndl L); boolean atFirst(ListHndl L); boolean atLast(ListHndl L); boolean offEnd(ListHndl L); int getFirst(ListHndl L); int getLast(ListHndl L); int getCurrent(ListHndl L); int getLength(ListHndl L); boolean equals(ListHndl A, ListHndl B); /***** Manipulation procedures ******/ void moveFirst(ListHndl L); void moveLast(ListHndl L); void movePrev(ListHndl L); void moveNext(ListHndl L); void insertBeforeFirst(ListHndl L, int data); void insertAfterLast(ListHndl L, int data); void insertBeforeCurrent(ListHndl L, int data); void insertAfterCurrent(ListHndl L, int data); void deleteFirst(ListHndl L); void deleteLast(ListHndl L); void deleteCurrent(ListHndl L);

/***** Other operations **********/

ListHndl copy(ListHndl L); void printList(ListHndl L);

Function NewList returns a ListHndl which points to a new empty list. Function FreeList frees all

memory associated with its ListHndl* 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.

ListHndl cat(ListHndl A, ListHndl B);

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 (ListDriver.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, Cats

ID, and student ID.

A simple Makefile for this assignment might look like:

Makefile for Programming Assignment 2

CMPS 101 Spring 3002

make makes Shuffle

make ListDriver makes ListDriver

make clean removes all object files

Shuffle : List.o Shuffle.o gcc -o Shuffle Shuffle.o List.o Shuffle.o : List.h Shuffle.c gcc -c -ansi -Wall Shuffle.c ListDriver: List.o ListDriver.o gcc -o ListDriver ListDriver.o List.o ListDriver.o : List.h ListDriver.c gcc -c -ansi -Wall ListDriver.c List.o : List.h List.c gcc -c -ansi -Wall List.c clean : rm Shuffle ListDriver Shuffle.o ListDriver.o List.o