#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).