题目描述

源代码
#include<iostream>
#include<stdlib.h>
#include<malloc.h>
using namespace std;
typedef char ElemType;
class SqList
{
public:
ElemType data[100];
int length;
};
void CreateList(SqList *&L,ElemType a[],int n)
{
int i=0,k=0;
L=(SqList *)malloc(sizeof(SqList));
while(i<n)
{
L->data[k]=a[i];
k++;i++;
}
L->length=k;
}
void InitList(SqList *&L)
{
L=(SqList *)malloc(sizeof(SqList));
L->length=0;
}
void Inverse(SqList *&L)
{
int i=0,k=L->length-1;
ElemType a[100];
while(i<L->length)
{
a[i]=L->data[k];
i++;k--;
}
i=0;
while(i<L->length)
{
L->data[i]=a[i];
i++;
}
}
void ShowList(SqList *L)
{
for(int i=0;i<L->length;i++)
{
if(i!=L->length)
{
cout<<L->data[i]<<" ";
}else
{
cout<<L->data[i];
}
}
}
int main()
{
int n;
ElemType a[100];
SqList *L;
cin>>n;
getchar();
for(int i=0;i<n;i++)
{
cin>>a[i];
}
CreateList(L,a,n);
Inverse(L);
ShowList(L);
return 0;
}