liunx c動態陣列

2021-10-23 05:20:42 字數 1518 閱讀 1711

功能

1.對陣列初始化

2. 檢測陣列是否為空

3. 遍歷陣列

4. 檢測陣列儲存滿了

5. 追加資料

6. 指定位置插入資料

7. 刪除指定位置的資料並返回該數字

8. 倒置

9. 陣列排序

#include

#include

#include

#include

typedef struct array

arr;

void init_arr(struct array * p,const int len); //對data初始化

bool is_empty(struct array * p); //檢測count是否為0

void show_arr(struct array * p); //輸出data

bool full_arr(struct array * p); //檢測len是否等於count

bool add_arr(struct array * p,const int val); //追加內容

bool insert_arr(struct array * p,const int pos,const int val); //指定位置插入數字

bool del_arr(struct array * p,const int pos,int * re); //刪除指定位置的數字,然後然後返所刪除的數字

bool inversion_arr(struct array * p); //倒置

bool sort_arr(struct array * p); //排序

int main()

void init_arr(struct array * p,const int len)

else

return;

}bool is_empty(struct array * p)

void show_arr(struct array * p)}}

bool add_arr(struct array * p,const int val)

else

return true;

}bool full_arr(struct array * p)

return true;

}bool insert_arr(struct array * p,const int pos,const int val)

p->data[pos - 1] = val;

p->count++;

return true;

}bool del_arr(struct array * p,const int pos,int * re)

}p->count–;

return true;

}bool inversion_arr(struct array * p)

return 0;

}bool sort_arr(struct array * p)}}

return true;

}

vba 陣列(動態陣列)

主要內容 本文章主要介紹vba中,陣列的使用,特別介紹動態陣列的使用,並有簡單事例,幫助理解。陣列是我們經常用到的儲存資料的一種媒介,他到底是什麼呢?陣列是具有相同資料型別並且共享乙個名字的一組變數的集合。通俗的說,陣列是變數。陣列的宣告 可以用dim語句或者public語句生命陣列。如 dim p...

陣列與動態陣列

int main other element will be set as the default value 2.get length int size sizeof a1 sizeof a1 cout the size of a1 is size endl 3.access element co...

動態陣列型別

在win32平台,動態陣列變數佔4位元組記憶體,包含乙個指向動態分配陣列的指標。當變數為空 未初始化 或者指向乙個長度為0的陣列時,指標值為nil且沒有與變數相關的動態記憶體。的對於非空的陣列,變數指向乙個動態分配的記憶體塊,包含額外的32位長度標示和32位引用計數。下表顯示了動態陣列記憶體塊的層次...