#include <stdio.h>
#include <stdlib.h>
typedef struct
{
size_t len;
int* ptr;
} int_arr;
int_arr* init(size_t cap);
int ia_set(int_arr* ia_p, size_t idx, int val);
int ia_get(int_arr* ia_p, size_t idx);
int ia_insert(int_arr* ia_p, size_t idx, int val);
int ia_delete(int_arr* ia_p, size_t idx);
int ia_push(int_arr* ia_p, int val);
int ia_pop(int_arr* ia_p);
int ia_sort(int_arr* ia_p, int order);
int main(){
int_arr* arr1 = init(5);
ia_set(arr1, 2, 1);
printf("%d\n", ia_get(arr1, 2));
ia_insert(arr1, 3, 10);
ia_delete(arr1, 3);
ia_push(arr1, 5);
printf("%d\n", ia_pop(arr1));
system("pause");
return 0;
}
int_arr* init(size_t cap){
int_arr arr;
int_arr* tmp = &arr;
arr.len = cap;
arr.ptr = (int*)malloc(sizeof(int)*arr.len);
for (int i = 0; i < arr.len; i++)
arr.ptr[i] = 0;
return tmp;
}
int ia_set(int_arr* ia_p, size_t idx, int val){
ia_p->ptr[idx] = val;
return ia_p->ptr[idx];
}
int ia_get(int_arr* ia_p, size_t idx){
return ia_p->ptr[idx];
}
int ia_insert(int_arr* ia_p, size_t idx, int val){
for (int i = ia_p->len; i >= idx; i--)
ia_p->ptr[i] = ia_p->ptr[i - 1];
ia_p->ptr[idx] = val;
ia_p->len++;
return ia_p->ptr[idx];
}
int ia_delete(int_arr* ia_p, size_t idx){
int tmp = ia_p->ptr[idx - 1];
for (int i = idx - 1; i < ia_p->len - 1; i++)
ia_p->ptr[i] = ia_p->ptr[i + 1];
ia_p->len--;
return tmp;
}
int ia_push(int_arr* ia_p, int val){
ia_p->ptr[ia_p->len++] = val;
return ia_p->ptr[ia_p->len - 1];
}
int ia_pop(int_arr* ia_p){
ia_p->len--;
return ia_p->ptr[ia_p->len];
}
int ia_sort(int_arr* ia_p, int order)