#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;
}
/***************************************************
User name: TJRAC6015203228魏杰
Result: Accepted
Take time: 0ms
Take Memory: 104KB
Submit time: 2016-11-01 13:31:55
****************************************************/
sdut2118数据结构实验之链表三:链表的逆置
最新推荐文章于 2023-07-27 20:10:03 发布