#include<iostream>
#include<stdio.h>
using namespace std;
#define MAXSIZE 20
typedef struct book
{
char a[10];
int b;
}book;
typedef struct List
{
int length;
book* elem;
}List;
bool Creatlist(List&L)
{
L.length = 0;
L.elem = new book[MAXSIZE];
if (L.elem) return true;//申请成功,就返回true
else return false;
}
void Destroy(List& L)
{
if(L.elem ) delete L.elem ;
}
void Delet(List& L)
{
L.length = 0;
}
bool Getelem(List& L, int i,book&k)
{
if (i<1 || i>L.length) return false;
k = L.elem[i - 1];//数组的下标从0开始,所以直接返回它的前一个就行
return true;
}
int main()
{
//创建一个空的线性表,但是要考虑空间问题,如果空间满了就无法创建,需要一个返回值判断是否完美创建
List L;
Creatlist( L);
//销毁线性表:就是将申请的空间释放
Destroy(L);
//清空线性表:将长度设置为0
Delet(L);
//取值:取出顺序表第i个位置的数据,但是第i个位置的数据储存在i-1这个位置上
//首先这个数要能取所以需要一个简单的判断
int i = 3;
book k;
Getelem(L,i,k);//复杂度O(1)
return 0;
}