#include "iostream"
using namespace std;

typedef struct{
    int tail;
    int head;
    int q[7];
}QUEUE;//队列数据结构定义

bool QUEUE_EMPTY(QUEUE &Q){
    if(Q.tail==Q.head)
        return true;
    else 
        return false;
}//判断队列是否已空

bool QUEUE_FULL(QUEUE &Q){
    if(Q.tail==6&&Q.head==1||Q.tail+1==Q.head)
        return true;
    else 
        return false;
}//判断队列是否已满

void ENQUEUE(QUEUE &Q,int x){
    if(QUEUE_FULL(Q))
        cout<<"队列已经满了!!!"<<endl;
    else{
        Q.q[Q.tail]=x;
        if(Q.tail==6)
            Q.tail=1;
        else
            Q.tail=Q.tail+1;
    }
}//入队列

int DEQUEUE(QUEUE &Q){
    int x;
    if(QUEUE_EMPTY(Q)){
        cout<<"队列已空!!!"<<endl;
        return -1;
    }
    
    else{
        x=Q.head;
        if(Q.head==6)
            Q.head=1;
        else 
            Q.head=Q.head+1;
        return x;
    }
}//出队列

void INIT_QUEUE(QUEUE &Q){
    Q.tail=Q.head=1;
}//初始化队列

void main(){
    QUEUE Q;
    INIT_QUEUE(Q);
    DEQUEUE(Q);
    for(int i=1;i<=6;i++)
        ENQUEUE(Q,i);
    getchar();
    getchar();
}//对队列进行调试

 

相关文章: