🎨 C 语言实现类似php的array数据类型
This commit is contained in:
parent
c4510afdec
commit
a30f7b3cd7
|
@ -89,13 +89,18 @@ void print_array(Array arr) {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Array arr;
|
Array arr;
|
||||||
|
//初始化数组
|
||||||
init_array(&arr, 10);
|
init_array(&arr, 10);
|
||||||
|
//插入int 类型的元素
|
||||||
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
||||||
*((int *)arr.data[0]->data) = 10;
|
*((int *)arr.data[0]->data) = 10;
|
||||||
|
//插入int 类型的元素
|
||||||
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
||||||
*((int *)arr.data[1]->data) = 20;
|
*((int *)arr.data[1]->data) = 20;
|
||||||
|
//插入int 类型的元素
|
||||||
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
push(&arr, &(Element){.data = malloc(sizeof(int)), .type = Inter});
|
||||||
*((int *)arr.data[2]->data) = 30;
|
*((int *)arr.data[2]->data) = 30;
|
||||||
|
//插入string类型的元素
|
||||||
push(&arr, &(Element){.data = strdup("zyimm"), .type = String});
|
push(&arr, &(Element){.data = strdup("zyimm"), .type = String});
|
||||||
print_array(arr);
|
print_array(arr);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user