Problem Description
Input
第二行依次输入每个整数。
Output
Example Input
8 12 56 4 6 55 15 33 62
Example Output
12 56 4 6 55 15 33 62
Hint
不得使用数组!
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*q;
int i;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
q=head;
int n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
q->next=p;
q=p;
}
q=head->next;
while(q!=NULL)
{
if(q->next==NULL)
printf("%d\n",q->data);
else
printf("%d ",q->data);
q=q->next;
}
return 0;
}