CSE 121 Spring 2003 Project 1
Due 22 April 2003
Problem Summary
This assignment is to help you become familiar with the C coding environment
and to build a data abstraction needed for future projects. Specifically,
you are asked to build the data abstraction of a queue manager. This should
be able to maintain a queue of arbitrary objects. Your abstraction will
allow one to create a new queue, destroy a queue, insert a value at the
end of a queue, return the first object from a queue, and determine (nondestructively)
whether or not a queue contains any elements.
Standard Header
We will provide you with a standard header file, called queue.h,
which you should #include in your program. You will probably
want to augment the header file to include your own definitions, but
you should leave what is there unchanged.
The header file provides the following definitions:
-
any_ptr: This type is useful for managing objects whose type you
don't want to declare. Any kind of pointer; for example, (char *), (int
*), etc., can be cast to an any_ptr, and vice versa.
-
Boolean: This type can have two values, TRUE (1) and FALSE (0).
Needed Routines
At the minimum you must write the routines described below. Their type
signatures are defined in queue.h.
Queue q_create()
This routine returns a newly allocated, empty queue.
void q_destroy(Queue q)
This routine destroys the queue, freeing up any memory allocated for it
and its parts. After this function, q is no longer a legal queue.
Note that if q is not empty, and contains dynamically allocated objects,
these will not get freed. Thus it is better to empty the queue via a loop
before calling here.
Boolean q_is_empty(Queue q)
Given a queue, this routine returns TRUE if q is empty, and FALSE
otherwise.
void q_insert(Queue q, any_ptr obj)
This routine places obj onto the end of q.
any_ptr q_remove (Queue q)
Returns NULL if q is empty. Otherwise, removes the first object from the
head of q, and returns it.
Testing
We will link a test program to your module(s) to test the required operations.
That is why we have provided you with the definitions in queue.h:
by including this header file, we will be able to test your package.
The test module, which includes main(), will be available for
public use in one week. When you hand in your program, your makefile should
link your modules with our test module to create an executable.
Documentation
This project is simple enough that we will only need a short document describing
your implementation. This document should be in the form of a README file
that describes your package and how it behaves (both under normal and under
exceptional conditions).
Turning In
You will turn in the project using turnin. The due date is 11:59
PM on Tuesday, 22 April 2003. Further details on how to turn in will be
posted to discus.
We will not accept late projects.