Cheet 3 队列

typedef Struct QNode
{
    int data;
    struct QNode *next;
}QNode, *QueuePtr;

struct LinkQueue
{
    QueuePtr front;
    QueuePtr rear;
};

入队

Q.rear->next = p;
Q.rear = p;

出队

p = Q.front->next;
Q.front->next = p->next;
if(Q.rear == p)
    Q.rear = Q.front;

循环队列

struct SqQueue
{
    int *base;
    int front, rear;
};

入队

Q.base[Q.rear] = e;
Q.rear = (Q.rear + 1)%MAXQSIZE;

出队

e = Q.base[Q.front];
Q.front = (Q.front + 1)%MAXQSIZE;

计算个数

(Q.rear + Q.front + MAXQSIZE)%MAXQSIZE;

你可能感兴趣的:(Cheet 3 队列)