主题:[讨论]特简单的程序帮忙看看
链表的建立和输出,运行时,输入十个数据不会自动结束,为什么,大家帮忙看一下吧
#define N 20
#include <stdio.h>
struct list
{
int data;
struct list *next;
}*head,*p,*q,*s;
void creat (struct list *head,int n)
{struct list *p,*s;
int i;
p=head;
printf("\nplease input the elem of linklist:\n");
for(i=1;i<=n;i++)
{s=(struct list *)malloc(sizeof(struct list));
scanf("%d\t",&s->data);
if(head==NULL) head=p=s;
else
{p->next=s;p=s;}s->next=NULL;}
}
void printout (struct list *head)
{struct list *p;
p=head->next;
printf("\nthe elem of linklist are:\n");
while(p)
{printf("%5d",p->data);
p=p->next;}
}ain()
{struct list *head,*p,*q,*s;
int n=10;
head=(struct list *)malloc(sizeof(struct list));
creat(head,n);
printout(head);}
#define N 20
#include <stdio.h>
struct list
{
int data;
struct list *next;
}*head,*p,*q,*s;
void creat (struct list *head,int n)
{struct list *p,*s;
int i;
p=head;
printf("\nplease input the elem of linklist:\n");
for(i=1;i<=n;i++)
{s=(struct list *)malloc(sizeof(struct list));
scanf("%d\t",&s->data);
if(head==NULL) head=p=s;
else
{p->next=s;p=s;}s->next=NULL;}
}
void printout (struct list *head)
{struct list *p;
p=head->next;
printf("\nthe elem of linklist are:\n");
while(p)
{printf("%5d",p->data);
p=p->next;}
}ain()
{struct list *head,*p,*q,*s;
int n=10;
head=(struct list *)malloc(sizeof(struct list));
creat(head,n);
printout(head);}