#include <stdio.h>
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*tail,*q,*r;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)break;
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
head->next=NULL;
q=p->next;
while(p)
{
p->next=head->next;
head->next=p;
p=q;
if(q)
q=q->next;
}
r=head;
while(r->next!=NULL)
{
printf("%d ",r->next->data);
r=r->next;
}
return 0;
}
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*tail,*q,*r;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)break;
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
head->next=NULL;
q=p->next;
while(p)
{
p->next=head->next;
head->next=p;
p=q;
if(q)
q=q->next;
}
r=head;
while(r->next!=NULL)
{
printf("%d ",r->next->data);
r=r->next;
}
return 0;
}