#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*head,*tail,*p,*q;
int n,t;
void built()
{
head=(struct node *)malloc(sizeof(struct node));
tail=head;
while(scanf("%d",&t)&&t!=-1)
{
p=(struct node *)malloc(sizeof(struct node));
p->data=t;
tail->next=p;
tail=p;
}
tail->next=NULL;
}
void print()
{
p=head->next;
while(p)
{
printf("%d",p->data);
if(p->next)
printf(" ");
p=p->next;
}
}
void res()
{
p=head->next;
head->next=NULL;
while(p)
{
q=p;
p=p->next;
q->next=head->next;
head->next=q;
}
}
int main()
{
built();
res();
print();
}
SDUT2118数据结构实验之链表三:链表的逆置
最新推荐文章于 2021-03-04 20:17:46 发布