- 2
- 0
- 约5.58万字
- 约 6页
- 2016-12-25 发布于河南
- 举报
#includestdio.h
#includemalloc.h
#includestdlib.h
struct node
{
int val;
struct node *next;
};
//创建一个链表
struct node* creat(struct node *head)
{
int num,i,x;
struct node *tail,*p;
head=tail=p=NULL;
scanf(%d,num); //输入链表的长度
tail=p;
for(i=0;inum;i++)
{
scanf(%d,x);
p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
{
printf(malloc defult);
exit(1);
}
p-val=x;
p-next=NULL;
if(head==NULL)
{
head=p;
tail=head; //必须有,否则报错
}
else
{
tail-next=p;
return head;
}
}
}
创建一个链表
typedef struct node
{ datatype data;
struct node *next;
原创力文档

文档评论(0)