#include<stdio.h>
#include<malloc.h>
#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList *L)
{L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType)) ;
if(!L->elem) exit(OVERFLOW);
L->length=0;
L->listsize=LIST_INIT_SIZE; /*内存容量100*/
return OK;
}
void Input_Sq(SqList *L)
{int length,i,x;
printf("/nPlease input the SList length:");
scanf("%d",&length);
L->length=length;
printf("/nPlease input %d elemts:",length);
for(i=0;i<length;i++)
{
scanf("%d",&x);
L->elem[i]=x;
}
}
void Output_Sq(SqList L)
{int i;
printf("/nThe list elemt:/n");
for(i=0;i<L.length;i++)
printf("%3d",L.elem[i]);
}
void Reverse_Sq(SqList *L)
//利用原表空间就地逆置顺序表L
{int i,len;
ElemType temp;
len=L->length;
for(i=0;i<len/2;i++)
{temp=L->elem[len-1-i];
L->elem[len-1-i]=L->elem[i];
L->elem[i]=temp;
}
}
void main()
{SqList L;
ElemType e;
InitList_Sq(&L);
Input_Sq(&L);
printf("/nBefore Reverse:");
Output_Sq(L);
Reverse_Sq(&L);
printf("/nAfter Reverse:");
Output_Sq(L);
}