#include <stdio.h> #include <stdlib.h> typedef int DataType; /*数据类型*/ typedef int ElemType; /*元素类型*/ //--------------线性表的动态顺序存储结构------------ #define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量 #define LISTINCREMENT 10 //线性表存储空间的分配增量 typedef struct { ElemType *elem; //存储空间基址 int length; //当前长度 int listsize; //当前分配的存储容量 }SqList; void InitList(SqList *L) //初始化 { L->elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));//分配空间 L->length = 0; //空表的长度为0 L->listsize = LIST_INIT_SIZE; //初始容量 } void CreateList(SqList *L, int n) { InitList(L); //初始化 int i; for(i = 0; i < n; i ++) { scanf("%d", &L->elem[i]); L->length++; } } void InsertList(SqList *L, int e) { int i; for(i = L->length-1; L->elem[i] > e; i--) //从顺序表最后一位开始,将所有大于e的元素向后移动 { L->elem[i+1] = L->elem[i]; } L->elem[i] = e; L->length++; } void ReverseList(SqList *L) { int i, temp; int n = L->length; for(i = 0; i < n/2; i ++) { temp = L->elem[i]; L->elem[i] = L->elem[n-1-i]; L->elem[n-1-i] = temp; } } void ListTraverse(SqList *L) { int n = L->length, i; for(i = 0; i < n; i++) printf("%d\n", L->elem[i]); } int main() { SqList L; int n; scanf("%d", &n); CreateList(&L, n); ReverseList(&L); ListTraverse(&L); return 0; }
数
最新推荐文章于 2021-03-20 23:01:32 发布