#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *next;
}LNode,*LinkList;
LinkList creat_list()
{
LinkList head=NULL;
head=(LinkList)malloc(sizeof(LNode));
if(head==NULL)
{
printf("memory out of use
");
return NULL;
}
head->next=NULL;
head->data=0;
return head;
}
int insert(LinkList head,int n)
{
for(int i=0;i<n;i++)
{
LinkList head_t=head->next;
LinkList new_node=NULL;
new_node=(LinkList)malloc(sizeof(LNode));
if(new_node==NULL)
{
printf("memory out of use
");
return -1;
}
printf("please input the value:
");
scanf("%d",&new_node->data);
new_node->next=head_t;
head->next=new_node;
}
return 0;
}
int show_list(LinkList head)
{
LinkList tem;
tem=head->next;
while(tem)
{
printf("%3d",tem->data);
tem=tem->next;
}
return 0;
}
int main()
{
LinkList head;
int n;
printf("please input the size which you want to insert
");
scanf("%d",&n);
head=creat_list();
insert(head,n);
show_list(head);
return 0;
}