#include<stdio.h>
#include<stdlib.h>
void main(){
struct node {
int data;
struct node *next;
};
struct node *p,*q,*k,*h;
int n,x,m,b=0;
printf("请输入链表的长度:");
scanf("%d",&m);
printf("请输入链表的值:");
scanf("%d",&n);
p=(struct node *)malloc(sizeof(struct node));
p->data=n;
k=p;
while (b<m-1){
scanf("%d",&n);
q=(struct node *)malloc(sizeof(struct node));
q->data=n;
k->next=q;
k=q;
b++;}
q->next=NULL;
h=p;
printf("尾插法插入值之后的链表为:");
while(h!=NULL){
printf("%d ",h->data);
h=h->next;}
printf("\n");}
该程序在Visual C++6.0上运行结果如下: