#define MaxSize 100 #include#include typedef struct { int data[MaxSize]; int front;//队头元素 int rear;//队尾元素指向队尾元素下一个位置 }SqQueue;//顺序存储队列 void InitQueue(SqQueue Q) { Q.front = Q.rear = 0;//初始化空队列 } bool isEmpty(SqQueue Q) { if (Q.front = Q.rear = 0) return true; else return false; }//判空 bool INQueue(SqQueue Q, int x) { if ((Q.rear + 1) % MaxSize == Q.front){ return false;//队列已满 } else { Q.data[Q.rear] = x; Q.rear = (Q.rear + 1) % MaxSize; } return true; }//入队 bool OUTQueue(SqQueue Q, int x) { if (Q.rear = Q.front = 0) { return false;//队列为空 } else { Q.data[Q.front] = x; Q.front = (Q.front + 1) % MaxSize; } return true; }//出队 typedef struct LNode { int data; struct LNode* next; }LNode;//定义结点 typedef struct LinkQueue { LNode* front;//队头指针 LNode* rear;//队尾指针 }LinkQueue;//定义链式存储队列 void InitQueue(LinkQueue Q) { Q.front = Q.rear = (LNode*)malloc(sizeof(LNode)); Q.front->next = Q.rear->next = NULL;//带头结点 }//初始化 bool isEmpty(LinkQueue Q) { if (Q.front != Q.rear) return false; else return true; }//判空 void INQueue(LinkQueue Q,int x) { LNode* s = (LNode*)malloc(sizeof(LNode)); s->data = x; Q.rear->next = s; Q.rear = s; }//入队 bool OUTQueue(LinkQueue Q, int x) { if (Q.front == Q.rear) return false; else { LNode* p = Q.front->next; p->data = x; Q.front->next = p->next; if (p->next == Q.rear) { Q.front == Q.rear; } free(p); } return true; }//入队



