#include <stdio.h>
#include <stdlib.h>
typedef int ElementType;
typedef struct Node *PtrToNode;
typedef struct Node {
ElementType Data;
PtrToNode Next;
}Node;
typedef PtrToNode List;
List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表 */
List Reverse( List L );
int main()
{
List L1, L2;
L1 = Read();
L2 = Reverse(L1);
Print(L1);
Print(L2);
return 0;
}/* 你的代码将被嵌在这里 */
List Reverse(List L)
{
List p,q;
p = L;
L = NULL;
while(p)
{
q = p;
p = p->Next;
q ->Next = L;
L = q;
}
return L;
}
List Read()
{
int i,N,a,first = 1;
List head,p,q;
scanf("%d",&N);
for(i = 0;i < N;i++)
{
scanf("%d",&a);
if(first)
{
head = (List)malloc(sizeof(Node));
head->Data = a;
head->Next =NULL;
p = head;
first--;
continue;
}
q = (List)malloc(sizeof(Node));
q->Data = a;
q->Next = NULL;
p->Next = q;
p = q;
}
return head;
}
void Print(List s)
{
List p = s;
while(p)
{
printf("%d ",p->Data);
p=p->Next;
}
printf("\n");
}