任务要求:
1.创建循环队列
2.链式实现
3.设置一个标志域tag,用它来判断front和rear相等时的队列情况。默认tag=0表示队列“空”
3.写出队列初始化,入队,出队函数
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
typedef int ElemType;
typedef struct LinkNode {
ElemType data;
LinkNode *next;
} LinkNode;
typedef struct {
LinkNode *front,*rear;
int tag;
} LinkQueue;
void Init(LinkQueue &Q) {
Q.front = Q.rear = (LinkNode *)malloc(sizeof(LinkNode));
Q.front->next = NULL;
Q.tag = 0;
}
bool QEmpty(LinkQueue Q) {
if(Q.front == Q.rear && Q.tag == 0)
return true;
return false;
}
void EnQueue(LinkQueue &Q,ElemType x) {
LinkNode *s = (LinkNode *)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
Q.tag = 1;
}
bool DeQueue(LinkQueue &Q,ElemTy