1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #define MAXSIZE 10
typedef struct SqQueue { int data[MAXSIZE]; int front, rear; int size; } SqQueue;
bool InitQueue(SqQueue* q) { q->front = q->rear =q->size= 0; return true; }
bool QueueEmpty(SqQueue* q) { if (q->size == 0) { return true; } return false; }
bool QueueFull(SqQueue* q) { if (q->size == MAXSIZE) { return true; } return false; }
bool EnQueue(SqQueue* q,int num) { if (QueueFull(q)) { return false; } q->data[q->rear] = num; q->rear = (q->rear + 1) % MAXSIZE; q->size++; return true; }
bool GetHead(SqQueue* q,int* p) { if (QueueEmpty(q)) { return false; } *p = q->data[q->front]; return true; }
bool DeQueue(SqQueue* q, int* p) { GetHead(q, p); q->front = (q->front + 1) % MAXSIZE; q->size--; return true; }
|