通过在CSDN上学习第一次将链表的创建完成。创建链表并且输出0到9的数。
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *createlist(struct node *head)
{
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
struct node *tail;
tail=head;
for(int i=0;i<10;i++)
{
struct node *str;
str=(struct node *)malloc(sizeof(struct node));
str->next=NULL;
str->data=i;
tail->next=str;
tail=str;
}
return head;
}
int printf(struct node *head)
{
head=head->next;
while(head!=NULL)
{
printf("%d\n",head->data);
head=head->next;
}
}
int main()
{
struct node *head;
head=createlist(head);
printf(head);
return 0;
}