#include<iostream> #include<vector> using namespace std; //结构定义 #define maxSize 50 typedef struct{ int data[maxSize]; int rear,prior; }SqQueue; void initQueue(SqQueue &Q){ Q.rear = 0; Q.prior = 0; } bool QueueEmpty(SqQueue Q){ if(Q.rear == Q.prior){ return true; } return false; } bool EnQueue(SqQueue &Q,int elem){ //查看队列是否已满,牺牲一个队列位置 if((Q.rear+1)%maxSize == Q.prior){ return false; } Q.data[Q.rear] = elem; Q.rear = (Q.rear + 1) % maxSize; return true; } bool DeQueu(SqQueue &Q,int &elem){ //查看队列是否为空 if(Q.rear == Q.prior){ return false; } elem = Q.data[Q.prior]; Q.prior = (Q.prior + 1) % maxSize; return true; }