#include <stdio.h>
#include <malloc.h> //malloch函数
#include <stdlib.h>//exit函数
#include <stdbool.h>
struct Arr
{
int *pBase;
int len;
int cnt;
};
bool append_arr();
void init_arr(struct Arr*,int );
bool delee_arr();
bool get_arr();
bool is_full();
bool is_empty();
void sotr_arr();
void show_arr();
void innversion_arr();
int main (void)
{
struct Arr arr;
init_arr(&arr,4);
append_arr(&arr,1);
append_arr(&arr,2);
append_arr(&arr,3);
append_arr(&arr,4);
show_arr(&arr);
return 0;
}
void init_arr(struct Arr*pArr,int length)
{
pArr->pBase = (int*)malloc(sizeof(int)*length) ;
if(NULL==pArr->pBase)
{
printf("动态内存分配失败!\n");
exit(-1);
}
else
{
printf("动态数组分配成功!\n");
pArr->len=length;
pArr->cnt=0;
}
return;
}
bool is_empty(struct Arr*pArr)
{
if(0==pArr->cnt)
return true;
else
return false;
}
void show_arr(struct Arr*pArr)
{
if(is_empty(pArr))
{
printf("数组为空\n");
}
else
{
for(int i=0;i<pArr->cnt;++i)
{
printf("%d",pArr->pBase[i]);
printf("\n");
}
}
printf("\n");
}
bool is_full(struct Arr*pArr)
{
if(pArr->cnt == pArr->len)
return true;
else
return false;
}
bool append_arr(struct Arr*pArr,int val)
{
if(is_full(pArr))
{
printf("数组已满\n");
return false;
}
else
{
pArr->pBase[pArr->cnt]=val;
(pArr->cnt)++;
return true;
}
}
bool innversion_arr(struct Arr*arr,int pos,int val)
{
int i;
if(is_full(pArr))
return false;
if(pos<1||pos>pArr->cnt+1)
return false;
for(i=pArr->cnt-1;i>)
{
}
}