初始化、判断队空:
void initQueue(LinkQueue& Q) {
Q.front = (LinkNode*)malloc(sizeof(LinkNode));
Q.rear = Q.front;
Q.front->next = NULL;
}
bool isEmpty(LinkQueue Q) {
if (Q.front == Q.rear)
return true;
else
return false;
}
入队、出队操作:
入队操作:
void enQueue(LinkQueue& Q, int x) {
LinkNode* s = (LinkNode*)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
}
出队操作:
bool deQueue(LinkQueue& Q, int& x) {
if (Q.front == Q.rear)
return false;
LinkNode* p = Q.front->next;
x = p->data;
//若只有一个元素???????
Q.front->next = p->next;
if (Q.rear == p)
Q.rear = Q.front;
free(p);
return true;
}