#include<iostream>
#include<vector>

using namespace std;

//结构定义
#define maxSize 50
typedef struct LinkNode{
    int data;
    struct LinkNode *next;
};
typedef struct{
    LinkNode *prior,*rear;
}LinkQueue;

void initLinkQueue(LinkQueue &Q){
    //带头结点的链表
    LinkNode *s = new LinkNode;
    s->next = nullptr;
    Q.prior = s;
    Q.rear = s;
}

bool IsEmpty(LinkQueue Q){
    if(Q.prior == Q.rear){
        return true;
    }
    return false;
}

void EnQueue(LinkQueue &Q,int elem){
    LinkNode *s = new LinkNode;
    s->data = elem;
    s->next = nullptr;
    Q.rear->next = s;
    Q.rear = s;
}

bool DeQueue(LinkQueue &Q,int elem){
    //判断队列是否为空
    if(Q.prior == Q.rear){
        return false;
    }
    LinkNode *p = Q.prior->next;
    elem = p->data;
    Q.prior->next = p->next;
    if(Q.rear == p){
        Q.rear = Q.prior;
    }
    free(p);
    return true;
}

   

posted on 2020-02-27 16:14  笨宝宝  阅读(144)  评论(0编辑  收藏  举报