c语言,关于链表,急急!!!!!

#include<stdio.h>#include<stdlib.h>structpoint{intx;structpoint*next;};structpoint*cr... #include<stdio.h>
#include<stdlib.h>

struct point
{
int x;
struct point *next;
};

struct point * create() ; // 定义一个create 的结构体函数 注:()不可省
struct point *insert(struct point *head,struct point *stud);
void print_point(struct point *head);

int main(void)
{

struct point *p,*head;
int x,choice;
int size=sizeof(struct point);

do{
printf("1:create 2:insert 3:print 0:exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
head=create();
break;

case 2:
printf("input number:\n");
scanf("%d",&x);
p=(struct point *)malloc(size);
p->x=x;
head=insert(head,p);
break;

case 3:
print_point(head);
break;

case 0:
break;
}
}
while(choice!=0);
return 0;
}

/*建立一个连表*/
struct point * create() // 定义一个create 的结构体函数 注:()不可省
{
int num;
int size=sizeof(struct point);
struct point *head,*p;
head=NULL; //开始时 头,尾 指针都为空
scanf("%d",&num);
while(num!=0)
{
p=(struct point *)malloc(size);
p->x=num; //num 通过 p 赋值到 x

head=insert(head,p);
scanf("%d",&num);

}
return head;
}

/*插入操作*/
struct point *insert(struct point *head,struct point *stud)
{
struct point *ptr,*ptr1,*ptr2;

ptr2 = head;

ptr=stud;

if(head==NULL)
{
head=ptr;
head->next=NULL;
}
else
{
while(( ptr->x>ptr2->x))&&(ptr->next!=NULL))
{
ptr1=ptr2;
ptr2=ptr2->next;
}
if(ptr->x <= ptr2->x)
{
if(head==ptr2) head=ptr;
else ptr1->next=ptr;
ptr->next=ptr2;
}

else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head;
}

/*遍历操作*/
void print_point(struct point *head)
{
struct point *ptr;
if(head==NULL)
printf("\n no records\n");
return ;
}
for(ptr=head;ptr;ptr=ptr->next)
printf("%d\n",p->x);
}
我这个程序错在哪???
展开
 我来答
希声和寡
推荐于2016-12-04 · TA获得超过2.6万个赞
知道大有可为答主
回答量:6437
采纳率:0%
帮助的人:3346万
展开全部
=======================
一共错了3个地方,都用////////////////////Error标注了,下面是帮你改了以后的代码:
#include<stdio.h>
#include<stdlib.h>

struct point
{
int x;
struct point *next;
};

struct point * create() ; // 定?一个create 的??体函数 注:()不可省
struct point *insert(struct point *head,struct point *stud);
void print_point(struct point *head);

int main(void)
{
struct point *p,*head;
int x,choice;
int size=sizeof(struct point);

do{
printf("1:create 2:insert 3:print 0:exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
head=create();
break;
case 2:
printf("input number:\n");
scanf("%d",&x);
p=(struct point *)malloc(size);
p->x=x;
head=insert(head,p);
break;
case 3:
print_point(head);
break;
case 0:
break;
}
}
while(choice!=0);
return 0;
}

/*建立一个?表*/
struct point * create() // 定?一个create 的??体函数 注:()不可省
{
int num;
int size=sizeof(struct point);
struct point *head,*p;
head=NULL; //?始? ?,尾 指?都?空
scanf("%d",&num);
while(num!=0)
{
p=(struct point *)malloc(size);
p->x=num; //num 通? p ??到 x

head=insert(head,p);
scanf("%d",&num);
}
return head;
}

/*插入操作*/
struct point *insert(struct point *head,struct point *stud)
{
struct point *ptr,*ptr1,*ptr2;
ptr2 = head;
ptr=stud;

if(head==NULL)
{
head=ptr;
head->next=NULL;
}
else
{
//while(( ptr->x>ptr2->x))&&(ptr->next!=NULL)) ////////////////////Error1
while(( ptr->x>ptr2->x)&&(ptr->next!=NULL))
{
ptr1=ptr2;
ptr2=ptr2->next;
}
if(ptr->x <= ptr2->x)
{
if(head==ptr2) head=ptr;
else ptr1->next=ptr;
ptr->next=ptr2;
}

else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head;
}

/*遍?操作*/
void print_point(struct point *head)
{
struct point *ptr;
//if(head==NULL) ////////////////////Error2
if(head==NULL){
printf("\n no records\n");
return ;
}
for(ptr=head;ptr;ptr=ptr->next)
//printf("%d\n",p->x); ////////////////////Error3
printf("%d\n",ptr->x);
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2008-12-26
展开全部
creat()函数的定义不存在

print_point()函数中的if(head==NULL)后面缺少一个左大括号"{"

print_point()函数中的printf("%d\n",p->x);应该是printf("%d\n",ptr->x);

insert()函数中的while(( ptr->x>ptr2->x))&&(ptr->next!=NULL))多了一个右括号,应改为while(( ptr->x>ptr2->x)&&(ptr->next!=NULL))
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
huafeng86999
2008-12-26 · TA获得超过277个赞
知道小有建树答主
回答量:262
采纳率:100%
帮助的人:269万
展开全部
while(( ptr->x>ptr2->x))&&(ptr->next!=NULL))
其中ptr->next!=NULL改成ptr2->next!=NULL
你再试一下
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式