/ ************************************************** ********************* REVISION log entry revision by: http://blog.9cbs.net/hongweijin revised on: 2004-10-14 18:05 : 29 Comments: General operation of the cycle queue **************************************************************** ***************************** /
#include
#define maxqsize 10 // Maximum queue length #define false 0 # Define true 1
Typedef int statness; typedef int qlemtype;
Typedef struct qlemtype * base; int around; @} sqqueue;
STATUS INTQUEUE (SQQQueue &); STATUS QueueLength; Status Enqueue (Sqqueue &, QelemType); Status Dequeue (Sqqueue &, QelemType);
Void main (void) {sqqueue queue; qlemtype element; int cable;
INTQUEUE (Queue); for (Client = 0; Client <3; Client ) {Scanf ("% D", & Element); Enqueue (Queue, Element);}
Printf ("/ n"); length = queuelength (queue);
For (Client = 0; Client While (QueueLength (Queue) Printf ("/ n"); length = queuelength (queue); For (Client = 0; Client } ////// Function Name: initQueue // Function Description: Initialize a loop queue // Parameter: SQQueue & queue // Return Value: status //// status initQueue (Sqqueue & queue) {queue.base = (QELEMTYPE *) Malloc (QELEMTYPE)); if (! Queue.base) Return False; queue.front = queue.rear = 0; Return True;} ////// Function Name: Queuelength // Function Description: Get the length of the queue // Parameters: SQQueue Queue // Return Value: status //////////////////////////////////////////////////////////> Queue.front maxqsize)% maxqsize;} ////// function name: enqueue // Function Description: Insert Element to Queue // Parameters: Sqqueue & Queue // Parameters: QELEMTYPE ELEMENT // Return Value: status // /// status enqueue (SQQQueue & queue, QELEMTYPE ELEMENT) {// Judgment is the unfull queue IF ((Queue.Rear 1)% maxqsize == queue.front) Return False; Queue.Base [queue.rear ] = ELEMENT; Queue.rear = (queue.rear 1)% Maxqsize; Return True;} ////// Function Name: DEQUEUE // Function Description: Delete Queue's Headjet // Parameters: Sqqueue & Queue // Parameters: QELEMTYPE & ELEMENT / / Return Value: status //// status Dequeue (Sqqueue & Queue , QELEMTYPE & ELEMENT) {// Judgment queue is empty if (Queue.Front == Queue.rear) Return False; element = queue.base [queue.front]; queue.front = (queue.front 1)% Maxqsize; Return True;}