数据结构实验之链表一:顺序建立链表
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
第二行依次输入每个整数。
输出
示例输入
8 12 56 4 6 55 15 33 62
示例输出
12 56 4 6 55 15 33 62
提示
来源
示例程序
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node*next;
};
int main()
{
struct node*head=NULL,*tmp=NULL,*now=NULL;
int i,j,m,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
tmp=(struct node*)malloc(sizeof(struct node));
if(head==NULL)
head=tmp;
else
now->next=tmp;
tmp->next=NULL;
scanf("%d",&tmp->data);
now=tmp;
}
tmp=head;
while(tmp!=NULL)
{
printf("%d",tmp->data);
if(tmp->next!=NULL)
printf(" ");
else
printf("\n");
tmp=tmp->next;
}
return 0;
}