设有一线性表A=(a0,a1,…, ai,…an-1),其逆线性表定义为A’=( an-1,…, ai,…,a1, a0),设计一个算法,将线性表逆置,要求线性表仍占用原线性表的空间。
输入格式
第一行:输入n,表示单链表的元素个数
第二行:输入单链表的各元素,用空格分开
输出格式
第一行:输出单链表逆置前的元素列表
第二行:输出单链表逆置后的元素列表
输入样例
8
32 97 54 65 35 84 61 75
输出样例
The List is:32 97 54 65 35 84 61 75
The turned List is:75 61 84 35 65 54 97 32
#include<stdio.h>
#include<malloc.h>
#define ERROR 0
#define OK 1
#define ElemType int
typedef int Status;
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
//创建链表
Status CreateLink_L(LinkList &L,int n)
{
LinkList p,q;
int i;
ElemType e;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
q=(LinkList)malloc(sizeof(LNode));
q=L;
for(i=0;i<n;i++)