# 逆置线性表(线性表)

（线性表）请写一个算法将顺序存储结构的线性表（a1...an）逆置为(an...a1)。

5 4 3 2 1

``````5
7 8 9 10 11 ``````

``11 10 9 8 7 ``

``````#include "stdio.h"
#define   maxsize   500
typedef   int    elemtype;
typedef   struct
{elemtype    data[maxsize];
int  last;
}sequenlist;
void   converse(sequenlist   *L)
{int  i;
elemtype   x;
for(i=0;i<L->last/2;i++)
{x=L->data[i];
L->data[i]=L->data[L->last-1-i];
L->data[L->last-1-i]=x;
}
}
main()
{int  i;
sequenlist   x,*L;
L=&x;
scanf("%d",&L->last);
for(i=0;i<L->last;i++)
scanf("%d",&(L->data[i]));
converse(L);
for(i=0;i<L->last;i++)
printf("%d ",L->data[i]);
}``````

``````#include<iostream>

using namespace std;

typedef struct node
{
int data;
node *next;
}sqlist;

void CreateList(sqlist *&L)
{
L = new sqlist();
L->next = NULL;
}

int main()
{
sqlist *L,*q;
CreateList(L);
q = L;
int N;
cin>>N;
int *a = new int[N];
int temp;
for(int i=0; i<N; i++)
{
cin>>temp;
sqlist *p =  new sqlist();
p->data = temp;
q->next = p;
p->next = NULL;
q = p;
}
q = L->next;
int n = 0;
while(q!=NULL)
{
a[n]=q->data;
q = q->next;
n++;
}
for(int m=N-1; m>=0; m--)
cout<<a[m]<<" ";
return 0;
}``````