高手麻烦看一看这个队列链表简单算法有什麼错呢??

来源:百度知道 编辑:UC知道 时间:2024/06/09 17:02:32
搞不懂是那里错,,请高手指点一下新手..

#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=Q.rear=(QNode*)malloc(sizeof(QNode)); //生成头结点
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;

#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 LinkQueue{
QueuePtr front;
QueuePtr rear;
}LinkQueue;

Status InitQueue(LinkQueue &Q)
{
Q.front=Q.rear=(QNode*)malloc(sizeof(QNode)); //生成头结点
if (!Q.front)
exit(OVERFLOW);
(Q.front)->next=NULL;
Q.rear->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)
{