关于链式队列的算法,求救!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/12 17:47:13
Queue.h

#define OVERFLOW -1
#define ERROR 0
typedef int ElemType;

typedef struct node
{ ElemType data;
struct node *next;
}Qnode,*Queueptr;

typedef struct
{
Queueptr front;//队头指针
Queueptr rear;//队尾指针
}Linkqueue;

void InitQueue(Linkqueue& Q);

void EnQueue(Linkqueue& Q,ElemType& e);

bool DeQueue(Linkqueue& Q,ElemType& e);

int QueueLength(Linkqueue& Q);

//void ClearQueue(Linkqueue& Q);

bool QueueEmpty(Linkqueue& Q);

int GetHead(Linkqueue& Q);

---------------------------------
---------------------------------
Queue.cpp

#include<iomanip.h>//流控制头文件,就像C里面的格式化输出一样.
#include<stdlib.h>
#include"Queue.h"

void InitQueue (Linkqueue& Q)
{
Q.front=Q.rear=(Queueptr)malloc(sizeof(Qnode));
Q.front->next=NULL;
}

QueueLenght有错,正确代码如下:
int QueueLength(Linkqueue& Q)
{
Queueptr p;
int i=0;
p = Q.front->next;
if (Q.rear == Q.front)
return i;
while(p!=Q.rear->next)
{
i++;
p=p->next;
}
return i;
}

GetHead代码有误,正确如下:

int GetHead(Linkqueue& Q)
{
return Q.front->next->data;
}

意见同上,我执行过了 ,改了就对了~
粗心哦,孩子~嘻嘻~