rear 指向实际的队列中元素
front指向前一个 当二者相等
相等 空or满?
#include <iostream>
using namespace std;
#define maxsize 100
typedef int elementtype;
struct qnode
{
elementtype data[maxsize];
int rear;
int front;
};
typedef struct qnode *queue;
//入队列
void addq(queue ptrq, elementtype item)
{
if ((ptrq->rear+1)%maxsize == ptrq->front)
{
cout << "man" << endl;
return;
}
ptrq->rear = (ptrq->rear + 1) % maxsize;
ptrq->data[ptrq->rear] = item;
}
//出队列
elementtype deleteq(queue ptrq)
{
if (ptrq->front == ptrq->rear)
{
cout << "kong";
return -1;
}
else
{
ptrq->front = (ptrq->front + 1) % maxsize;
return ptrq->data[ptrq->front];
}
}