/****************************************************************/
/* queue.h                                                      */
/* Justin Hartman                                               */
/* EECS 338 - Spring 2003                                       */
/* Assignment 5                                                 */
/****************************************************************/

/****************************************************************/
/* Acknowledgment:                                              */
/* This code was written by and borrowed from the               */
/* computer science department at Appalachian State             */
/* University:                                                  */
/* http://www.cs.appstate.edu/~crr/cs2440/oldexamples/queue.html*/
/****************************************************************/

/****************************************************************/
/* Written in Microsoft Visual C++ .NET                         */
/* Compiled and executed on CWRU's EECS department              */
/* lab's (Olin 404.5) SUN boxes using SSH and                   */
/* secure FTP                                                   */
/****************************************************************/

/* Maximum number of entries in the queue */
#define MAXQUEUE 100

/* We're putting ints in the queues today */
typedef int item_type;

/* The data type for a queue */
typedef struct queue_s {
   int count;
   int front;
   int rear;
   item_type data[MAXQUEUE];
} queue;

int cinc (int *i) {
   return (*i = (*i+1) % MAXQUEUE);
}

int full(queue *q) {
   return (q->count >= MAXQUEUE);
}

int empty (queue *q) {
   return (!q->count);
}

void initialize (queue *q) {
   q->count = 0;
   q->front = 0;
   q->rear  = -1;
}
int insertq (item_type c, queue *q) {
   if ( full (q)) return (0);
   q->count++;
   q->data[ cinc(&(q->rear)) ] = c;
   return (1);
}

item_type removeq (queue *q) {
   item_type c;

   if ( empty(q) ) return ('\0');
   c = q->data[ q->front ];
   q->count--;
   cinc( &(q->front) );
   return (c);
}

int count(queue *q) {
	return (q->count);
}