#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node next;
}Node;
Node CreatList(int n)
{
Node *head,p,end;
head=(Node)malloc(sizeof(Node));
end=head;
for(int i=0;i<n;i++)
{
p=(Node*)malloc(sizeof(Node));
scanf("%d",&p->data );
end->next=p;
end=p;
}
end->next=NULL;
return head;
}
Node ReverseList(Node *head)
{
Node *newHead;
if(head==NULL||head->next==NULL)
return head;
newHead=ReverseList(head->next);
head->next->next=head;
head->next=NULL;
return newHead;
}
void ShowList(Node *phead)
{
for(phead=phead->next;phead!=NULL;phead=phead->next)
printf("%d ",phead->data);
printf("\n");
}
int main(void)
{
Node *phead;
int n;
scanf("%d",&n);
phead = CreatList(n);
printf("链表逆置前的数据:\n");
ShowList(phead);
phead = ReverseList(phead);
printf("链表逆置后的数据:\n");
ShowList(phead);
return 0;
}