主题:我新来的,照顾一下啊,帮帮忙,都困扰我两天两夜了……
天上人间郁闷
[专家分:0] 发布于 2009-04-16 20:51:00
帮忙修改一下,看哪儿有错误,我实在看不出来……都快急死了……
回复列表 (共4个回复)
沙发
刚刚xue [专家分:10] 发布于 2009-04-16 23:17:00
看不到你的程序呀![em18]
板凳
天上人间郁闷 [专家分:0] 发布于 2009-04-17 12:43:00
这就是我的程序,麻烦您帮我看一下了,不胜感激~~~
#include "stdio.h"
#include "stdlib.h"
typedef struct Qnode{
int data;
struct Qnode *next;
}Qnode,*queueptr;
typedef struct{
queueptr front;
queueptr rear;
}linkqueue;
linkqueue q;
void creatqueue();
{
printf("jian li kong lian biao:\n");
q.front=q.rear=(queueptr)malloc(sizeof(Qnode));
q.front->next=NULL;
}
void insert()
{
int e;queueptr p;
printf("insert letter:");
scanf("%d",&e);
p=(queueptr)malloc(sizeof(Qnode));
p->next=NULL;
p->data=e;
q.rear->next=p;
q.rear=p;
}
void delet()
{ printf("shan chu lian biao zhong jin you de yuan su");
queueptr p;
p=q.front->next ;
q.front->next=p->next;
free(p);
}
void display()
{ queueptr p;
p=q.front->next;
while(p!=NULL)
{printf("\n输出练队列:\n");
printf("%d",p->data);
p=p->next;}
}
void main()
{
int i,j;
while(j)
{
printf("\n 1--- creatqueue ");
printf("\n 2---insert ");
printf("\n 3--- delet ");
printf("\n 4---exit ");
printf("\n请选择(0---4):");
scanf("%d",&i);
if(i==1)
{
creatqueue();
display();
}
else if(i==2)
{insert();
display();
}
else if(i==3)
{
delet();
display();
}
else if(i==4)
{
j=0;
printf("\n exit \n");
}
}
3 楼
小令00 [专家分:1040] 发布于 2009-04-19 07:51:00
题目?
你的错误具体是什么?
语法错误还是逻辑错误?
4 楼
MinQuanRen [专家分:190] 发布于 2009-04-21 18:21:00
错误是你在各个函数里没有对当前队列做判断。我对你的代码简单修改了以下如下:
typedef struct _Qnode
{
_Qnode()
{
data = 0;
next = NULL;
}
int data;
struct _Qnode *next;
}Qnode, *PQnode;
typedef struct _linkqueue
{
PQnode front;
PQnode rear;
}linkqueue;
linkqueue g_queue;
void creatqueue()
{
if (g_queue.front != NULL || g_queue.rear != NULL)
{
printf("queue is exist.\n");
return;
}
PQnode pnode = (PQnode)malloc(sizeof(Qnode));
pnode->next = NULL;
g_queue.front = g_queue.rear = pnode;
printf("create queue successful.\n");
}
void insert()
{
if (g_queue.front == NULL || g_queue.rear == NULL)
{
printf("queue is not exist.\n");
return;
}
int e = 0;
PQnode p = NULL;
printf("insert item(please input data):");
scanf("%d",&e);
p=(PQnode)malloc(sizeof(Qnode));
p->next=NULL;
p->data=e;
g_queue.rear->next=p;
g_queue.rear=p;
}
void delet()
{
if (g_queue.front->next == NULL)
{
printf("no item in the current queue.\n");
return;
}
printf("delete item\n");
PQnode p = NULL;
p=g_queue.front->next ;
g_queue.front->next=p->next;
free(p);
}
void display()
{
if (g_queue.front->next == NULL)
{
printf("no item in the current queue.\n");
return;
}
PQnode p = NULL;
p=g_queue.front->next;
printf("the current queue is:\n");
while(p != NULL)
{
printf("%d ",p->data);
p = p->next;
}
printf("\n");
}
int main(int argc, char* argv[])//_TCHAR
{
system("color 5A");
system("pause");
int i = 0;
bool bExit = true;
printf("\n 1--- creatqueue ");
printf("\n 2---insert ");
printf("\n 3--- delet ");
printf("\n 4---exit ");
printf("\n please select(0---4):");
while(bExit)
{
scanf("%d",&i);
if(i==1)
{
creatqueue();
display();
}
else if(i==2)
{
insert();
display();
}
else if(i==3)
{
delet();
display();
}
else if(i==4)
{
bExit = false;
printf("\n exit \n");
}
else
{
printf("sorry, no operate! the program will be exit.\n");
bExit = 0;
}
}
return 0;
}
我来回复