请高手解答一下这个队列链表小问题~~

来源:百度知道 编辑:UC知道 时间:2024/05/12 10:10:19
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
using namespace std;

typedef int Status,QElemType;

typedef struct QNode{
QElemType data;
struct QNode* next;
}QNode,*QueuePtr;

typedef struct{
QueuePtr front;
QueuePtr rear;
}LinkQueue;

Status InitQueue (LinkQueue &Q) {
Q.front=(QNode*)malloc(sizeof(QNode)); //生成头结点
Q.rear=Q.front;
if (!Q.front)
exit(OVERFLOW);
Q.front->next=NULL;
return OK;
}

Status DestroyQueue (LinkQueue &Q) {
QNode* p;
while (Q.front) {
p=Q.front->next;
free(Q.front); //释放Q.front指针指向结点的内存
Q.front=p; //Q.front后移
}
return OK;
}

Status ClearQueue (LinkQueue &Q) {
QNode* p;
while (Q.front->next) { //保留头结点,由第一个结点开始释放
p=Q.front->next->next;
free(Q.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
using namespace std;

typedef int Status,QElemType;

typedef struct QNode{
QElemType data;
struct QNode* next;
}QNode,*QueuePtr;

typedef struct{
QueuePtr front;
QueuePtr rear;
}LinkQueue;

Status InitQueue (LinkQueue &Q) {
Q.front=(QNode*)malloc(sizeof(QNode)); //生成头结点
Q.rear=Q.front;
if (!Q.front)
exit(OVERFLOW);
Q.front->next=NULL;
return OK;
}

Status DestroyQueue (LinkQueue &Q) {
QNode* p;
while (Q.front) {
p=Q.front->next;
free(Q.front); //释放Q.front指针指向结点的内存
Q.front=p; //Q.front后移
}
return OK;
}

Status ClearQueue (LinkQueue &Q) {
QNode* p;
while (Q.front->next) { //保留头结点,由第一个结点开始释放
p=Q.front->next-&