#include<stdio.h>
 #include<malloc.h>
 //#define LIST_INIT_SIZE 100;//线性表存储空间的初始分配量
 //#define LISTINCREMENT 10;//线性表存储空间的增量

 typedef struct xianxing {

     int* elem;//空间存储地址
     int length;//当前长度
     int listsize;//当前分配的存储容量

 } SqList,*PSqList;

 PSqList InitList(SqList* L);//返回指针地址

 bool addValue(PSqList L,int a);//增加一个数字到后面去
 void showXianXing(PSqList L);//显示线性表的全部元素
 bool deleteLastValue(PSqList L);//删除最后一个元素
 bool alertValue(PSqList L,int value);//更改最后一个值
 bool insertValue(PSqList L,int posti,int value);//指定一个位子插入
 bool deletePosValue(PSqList L,int posti);//指定一个位子的删除
 bool CheckIsEmpty(PSqList L);//检查是不是为空
 bool clearList(PSqList L);//清空表
 int  getListNum(PSqList L);//返回当前数组的个数
 int  getAllListNum(PSqList L);
 int main(void){

   //  SqList* pSqList = (SqList*)malloc(sizeof(SqList));
      SqList* pSqList = NULL;

     PSqList initialSqList = InitList(pSqList);

     if(initialSqList->listsize>0){
         printf("%d\n",initialSqList->listsize);
         printf("initial is successful!!!\n");
     }

     bool isAddRight = addValue(initialSqList,1);
     bool isAddRightx = addValue(initialSqList,2);
     addValue(initialSqList,3);
     addValue(initialSqList,4);
     addValue(initialSqList,5);
     addValue(initialSqList,6);
     addValue(initialSqList,7);
     addValue(initialSqList,8);
      
       int ax = 0;
       if(isAddRight){
          printf("add is successful!!!\n");
          ax =  initialSqList->elem[1];
          printf("##########%d\n",ax);
          int b=  initialSqList->length;
          printf("%d\n",b);
      }

   showXianXing(initialSqList);
   printf("\n");
   deleteLastValue(initialSqList);
   printf("\n");
   showXianXing(initialSqList);
   printf("\n");
   deleteLastValue(initialSqList);
   printf("\n");
   showXianXing(initialSqList);
   printf("\n");

   insertValue(initialSqList,3,999);
     showXianXing(initialSqList);
     printf("\n");
     insertValue(initialSqList,3,9991);
     showXianXing(initialSqList);
     return 0;
 }

 //初始化线性列表
 SqList* InitList(SqList* L){

     L = (SqList*)malloc(sizeof(SqList));//初始化指针

     bool isRight = true;

     L->elem = (int *)malloc(sizeof(int)*100);

     if(!L->elem){
     
         isRight = false;
     }
     L->length = 0;
     L->listsize = 100;

     return L;

 }

 //增加一个值
 bool addValue(PSqList L,int a){

     bool isRight = true;
     int nowLenght = L->length;//当前长度,数组的个数a[5] = {3,2,3,4,3}
     int allLenght = L->listsize;//当前可容纳的个数
     if(nowLenght >=allLenght){
     
         return false;
     }

      L->elem[L->length] = a;
      L->length = nowLenght +1;

     return true;
 }

 //显示所有值
 void showXianXing(PSqList L){

     if(L==NULL&&L->length==0){
         printf("线性表没有值或者为被初始化");
         return ;
     }
     for(int i=0;i<L->length;i++){
     
         printf("%d ",L->elem[i]);
     }

     return ;

 }

 //检查是不是为空
 bool CheckIsEmpty(PSqList L){

     int nowLength = L->length;
     if(nowLength == 0){
     
         return true;
     }
     return false;
 }

 //删掉最后一个值
 bool deleteLastValue(PSqList L){
     
     if(L->length == 0){
     
         return false;
     }

     L->elem[L->length-1] = NULL;
     L->length = L->length -1;
     
     return true;
 }

 //返回当前数组的个数
 int getListNum(PSqList L){

     return L->length;

 }

 //返回最大的容纳的数据
 int  getAllListNum(PSqList L){

     return L->listsize;
 }

 bool insertValue(PSqList L,int posti,int value){

     if(posti<0||posti>L->length||L->length==L->listsize){
     
         return false;
     }


     int a = 0;
     int b = posti;
     L->length = L->length +1;
     for(posti;posti<L->length+1;posti++){
         
         a = L->elem[posti];
         L->elem[posti] = value;
         value = a;

     }
        // L->elem[posti] = value;
     return true;
     }