数组实现(这里实现三个方法):
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
struct Arr{
int * pBase; //存储数组第一个元素的地址
int len; //数组所能容纳最大元素的个数
int cnt; //当前数组元素的个数
};
void init_arr(struct Arr * pArr,int lenth); //初始化数组
bool append_arr(); //追加
bool insert_arr();
bool delete_arr();
int get();
bool is_empty(struct Arr * pArr); //判断数组是否为空
bool is_full();
void sort_arr(); //排序
void show_arr(struct Arr * pArr);
void inversion_arr();
int main(void) {
struct Arr arr;
init_arr(&arr,6);
show_arr(&arr);
printf("%d\n", arr.len); //
while (true){}
return 0;
}
//初始化数组
void init_arr(struct Arr * pArr ,int lenth) {
pArr->pBase = (int *)malloc(sizeof(int) * lenth);
if (NULL==pArr->pBase) {
printf("动态内存分配失败!\n");
exit(-1);
}else {
pArr->len = lenth;
pArr->cnt = 0;
}
return;
}
//展示数组
void show_arr(struct Arr