/*********************************************************************************** Engineering 3891 Advanced Structured Programming Assignment: 4 Date Due: October 12th/2000 Name: Daryl Martin Student #: 9713520 Username: darylm ***********************************************************************************/ #include "assign4.h" namespace std { int queue[QSIZE]; //This will declare the size of the Queue from assign4.h int *tail = queue; //Next open postion in the queue int *head = queue; //The head queue item status currentStatus = EMPTY; //The current status of the Queue } using namespace std; /*********************************************************************************** * getStatus -- Returnns the current status of teh queue * * Parameters: * None * * Modifies: none * * Returns: The current status of the queue Date: 10/12/00 ***********************************************************************************/ status getStatus (void) { return currentStatus; } /*********************************************************************************** * putQueue -- Takes a number and places it into the queue at the tail if * their is room * * Parameters: * item -- the intereger to put into the queue * * Modifies: none * * Returns: The current status of the queue Date: 10/12/00 ***********************************************************************************/ status putQueue (int item) { if (currentStatus == FULL) currentStatus = OVERFLOW; //Overflow status if (currentStatus != OVERFLOW) //!= OVERFLOW shows us that their is room left { *tail = item; tail++; currentStatus = PENDING; if ((tail - queue) == QSIZE) tail = queue; //If it went to the end go back if (tail == head) currentStatus = FULL; //Move to the Head.... } return currentStatus; } /*********************************************************************************** * getQueue -- This will return the value at the first element. * If none then a zero will be returned. * * Parameters: * None * * Modifies: none * * Returns: The first value of the queue. A zero if non exist Date: 10/12/00 ***********************************************************************************/ int getQueue (void) { int zeroTerm = 0; //In case the queue is zero if (currentStatus == EMPTY) currentStatus = UNDERFLOW; //Nothign in the head. Hence the Underflow if (currentStatus != UNDERFLOW) //If the elemet's exist at *head { zeroTerm = *head; head++; if (head == (queue + QSIZE)) head = queue; //if you pass the end of the queue reset it if (tail == head) currentStatus = EMPTY; else currentStatus = PENDING; } return zeroTerm; }