# include <stdio.h>
# include <stdlib.h>
struct node
{
int val;
struct node *next;
};
void linked_list_insert_after(struct node *head,int n);
int linked_list_traverse(struct node *head);
int main()
{
struct node *head=(struct node *)malloc(sizeof(struct node));
linked_list_insert_after(head,10);
linked_list_traverse(head);
}
void linked_list_insert_after(struct node *head,int n)
{
struct node *node , *end ;
int i;
printf("请输入值\n");
for(i=0 ; i<n ; i++ )
{
node=(struct node *)malloc(sizeof(struct node));
scanf("%d",&node->val);
node->next=NULL;
if(i==0)
{
head=node;
head->next=NULL;
end=head;
}
else
{
end->next=node;
end=node;
}
}
end->next=NULL;
}
int linked_list_traverse(struct node *head)
{
struct node *p=head;
if(p==NULL)
{
printf("此链表为空\n");
return -1;
}
else
{
printf("输出链表中的值\n");
while(p!=NULL)
{
printf("%d\n",p->val);
p=p->next;
}
return 0;
}
}
输不出来值