标题:求助链表...无助ing!
取消只看楼主
y218z903
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-7-27
 问题点数:0 回复次数:3 
求助链表...无助ing!

#include"stdio.h"
#include"malloc.h"
#include"conio.h"
typedef struct stu
{
int num;
struct stu *next;

} node;
node *crtlink(node *head,int n)
{
node *p,*s;
int i;
s=head;
for(i=0;i<n;i++)
{
p=(node *)malloc(sizeof(node));
printf("请输入第%d个数据:",i+1);
scanf("%d",&p->num);
s->next =p;
s=p;

}
p->next=NULL;
return head;
}

void display(node *head)
{
node *p;
p=head->next;
while(p)
{
printf("输出刚刚的数据为:%d",p->num);
p=p->next;
}

}
int main(void)
{
node *head;
int n;
head=(node *)malloc(sizeof(node));

printf("请输入你所需要创建的数据的长度: \n");

scanf("%d",&n);
head=crtlink(head,n);
display(head);
return 0;
}
提示 ;The program 'D:\C++\MSDEV98\MYPROJECTS\链表\Debug\链表.exe' has exited with code 0 (0x0).

搜索更多相关主题的帖子: 链表 ing 
2007-10-15 17:23
y218z903
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-7-27
得分:0 

希望多指出代码的错误点及格式....


2007-10-15 17:25
y218z903
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-7-27
得分:0 
我用的是vc++6.0  编译器环境。?  如何检查?

2007-10-15 17:50
y218z903
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-7-27
得分:0 

#include"stdio.h"
#include"malloc.h"
#include"conio.h"
typedef struct stu
{
int num;
struct stu *next;

} node;
node *crtlink(node *head,int n)
{
node *p,*s;
int i;
s=head;
for(i=0;i<n;i++)
{
p=(node *)malloc(sizeof(node));
printf("请输入第%d个数据:",i+1);
scanf("%d",&p->num);
s->next =p;
s=p;

}
p->next=NULL;
return head;
}

void display(node *head)
{
node *p;
p=head->next;
while(p)
{
printf("输出刚刚的数据为:%d\n",p->num);
p=p->next;
}

}
void nizhi(node *head)
{
node *p,*s;
p=head->next;
head->next=NULL;
while(p)
{
s=p;p=p->next;
p->next=head->next;
head->next=s;
}
}
int main(void)
{
node *head,*p;
int n;
head=(node *)malloc(sizeof(node));

printf("请输入你所需要创建的数据的长度: \n");

scanf("%d",&n);
head=crtlink(head,n);
display(head);
nizhi(&head);
display(head);
getch();
return 0;
} 我换了个编译器,,,之后就行了,,不过我另外增加了个逆置的函数..之后又出错...


2007-10-15 18:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-177849-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030210 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved