链队列找错 输不出来

来源:百度知道 编辑:UC知道 时间:2024/05/31 10:15:58
编译没问题!就是输不出来!各位大哥救命啊啊啊!先给20分再追加10分
//队列的操作,主要包括入,出队
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
//宏定义
#define OK 1
#define ERROR -1
#define OVERFLOW -1
#define ENDFLAG '#'
#define TRUE 1
#define FALSE -1
//存储定义
typedef char QElemType;
typedef int status;
typedef struct Queue
{
QElemType data;
struct Queue *next;
}Queue;
//头指针和尾指针
typedef struct
{
Queue *front;
Queue *rear;
}LinkQueue;
//初始化队列
status InitQueue(LinkQueue *q)
{
q->front=q->rear =NULL; //----无头结点
return OK;
}
/*判断队列是否为空*/
status QueueEmpty(LinkQueue *Q)
{
return (Q->front==NULL)&&(Q->rear==NULL);
/*实际上只须判断队头指针是否为空即可*/
}
//入队
void EnQueue(LinkQueue *q,QElemType e)
{
Queue *p;
p=(Queue *)malloc(sizeof(Queue));/*申请新结点*/

插入和删除函数都用指针作参数,这样才能保证对同一个链表操作,还有打印里的while的结束条件不对,修改后如下,编译执行测试通过:
//队列的操作,主要包括入,出队
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
//宏定义
#define OK 1
#define ERROR -1
#define OVERFLOW -1
#define ENDFLAG '#'
#define TRUE 1
#define FALSE -1
//存储定义
typedef char QElemType;
typedef int status;
typedef struct Queue
{
QElemType data;
struct Queue *next;
}Queue;
//头指针和尾指针
typedef struct
{
Queue *front;
Queue *rear;
}LinkQueue;
//初始化队列
status InitQueue(LinkQueue *q)
{
q->front=q->rear =NULL; //----无头结点
return OK;
}
/*判断队列是否为空*/
status QueueEmpty(LinkQueue *Q)
{
return (Q->front==NULL)&&(Q->rear==NULL);
/*实际上只须判断队头指针是否为空即可*/
}
//入队
void EnQueue(LinkQueue *q,QElemType e)
{
Queue *p;