回 帖 发 新 帖 刷新版面

主题:循环队列

main()
{LinkQueue Q; int e=1;
 InitQueue(Q);
 printf("请输入队列元素:\n");//输入元素,直到输入的元素为0
 while(e)
 {scanf("%d",&e);
 if(e) EnQueue(Q,e);
 }
 printf("\n请输出队列中的元素:");
 OutQueue(Q);
 DeQueue(Q,e);
 printf("\n删除的队头元素是%d",e);
 printf("\n请输出队列中的元素:");
 OutQueue(Q);
 printf("\n");
 //DestroyQueue(Q);
 
}
调试以上程序时,在调用最后一个函数时,注释后不会出任何错误,不注释掉的话,结果可以出来,但是系统会提示一个错误信息,不知是什么原因,请高手指点一下

回复列表 (共5个回复)

沙发

拜托给个完整的,好不?

板凳

你对队列的基本定义都没有,就直接用了,当然不行了,
ADT QUEUE{...........
 ............. 
.............. 
}

3 楼

数据结构不能直接找书抄

4 楼

#include <stdio.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define NULL 0
typedef int Status;
typedef struct QNode
{int data;
 struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{QueuePtr front;
 QueuePtr rear;
}LinkQueue;
Status InitQueue(LinkQueue &Q)
{//构造一个空队列
 Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
 if(!Q.front) return ERROR;
 Q.front->next=NULL;
 return OK;
}
Status DestroyQueue(LinkQueue &Q)
{//销毁队列Q
 while(Q.front)
 {Q.rear=Q.front->next;
  free(Q.front);
  Q.rear=Q.front;
 }
 return OK;
}
Status EnQueue(LinkQueue &Q,int e)
{//插入元素e为Q的新队尾元素
 QueuePtr p;
 p=(QueuePtr)malloc(sizeof(QNode));
 if(!p) return ERROR;
 p->data=e;
 p->next=NULL;
 Q.rear->next=p;
 Q.rear=p;
 return OK;
}
Status DeQueue(LinkQueue &Q,int &e)
{//若队列不空,则删除Q队头元素,用e返回其值,并返回OK,否则返回ERROR
QueuePtr p;
if(Q.rear==Q.front) return ERROR;
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.rear==p) Q.rear=Q.front;
free(p);
return OK;
}
void OutQueue(LinkQueue Q)
{QueuePtr p;
p=Q.front->next;
while(p)
{printf("%3d",p->data);p=p->next;
}
}
/*void OutQueue(LinkQueue &Q)        //Output()  sub-function
{   QNode *p;
    p=Q.front;
    //cout<<"Queue : ";
    while(p!=Q.rear)
    {  p=p->next;
       printf("%3d",p->data);
    }
    printf("\n");
} //OutQueue() end*/
main()
{LinkQueue Q; int e=1;
 InitQueue(Q);
 printf("请输入队列元素:\n");//输入元素,直到输入的元素为0
 while(e)
 {scanf("%d",&e);
 if(e) EnQueue(Q,e);
 }
 printf("\n请输出队列中的元素:");
 OutQueue(Q);
 DeQueue(Q,e);
 printf("\n删除的队头元素是%d",e);
 printf("\n请输出队列中的元素:");
 OutQueue(Q);
 printf("\n");
 DestroyQueue(Q);
 
}
各位对不住啊,这回完整的程序给出来了,大家 帮忙看看

5 楼

怎么可能和注释有关?

1、C语言中的注释只有/* */,2、把注释内容放到VC或其它有着色功能的编译器上,一看就会明白,有可能是哪个地方注释漏了。

我来回复

您尚未登录,请登录后再回复。点此登录或注册