-
Notifications
You must be signed in to change notification settings - Fork 54
/
test-array.c
86 lines (58 loc) · 1.42 KB
/
test-array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include"array.h"
typedef struct _stud
{
AS_ARRAY_ITEM;
int id;
char *name;
int score;
}stud_t;
int main(int argc, char **argv)
{
array aarray;
array_init(&aarray);
stud_t stud0;
stud0.id = 0;
stud0.name = "0-stud";
stud0.score = 90;
stud_t stud1;
stud1.id = 1;
stud1.name = "1-stud";
stud1.score = 30;
stud_t stud2;
stud2.id = 2;
stud2.name = "2-stud";
stud2.score = 20;
stud_t stud3;
stud3.id = 3;
stud3.name = "3-stud";
stud3.score = 30;
stud_t stud4;
stud4.id = 4;
stud4.name = "4-stud";
stud4.score = 40;
array_push_back(&aarray, &stud0);
array_push_back(&aarray, &stud1);
array_push_back(&aarray, &stud2);
array_push_back(&aarray, &stud3);
array_insert_before(&aarray, 4, &stud4);
array_item *item = NULL;
printf("array size = %ld\n", get_array_size(&aarray));
int from = 0;
array_for_each(&aarray, item, from)
{
stud_t *temp = (stud_t *)item;
if(temp != NULL)
{
printf("array_get: id=%d, name=%s, score=%d\n",temp->id, temp->name, temp->score);
}
}
printf("array_find_by_index:6\n");
item = array_find_by_index(&aarray, 6);
if(item != NULL)
{
stud_t *temp = (stud_t *)item;
printf("array_get: id=%d, name=%s, score=%d\n",temp->id, temp->name, temp->score);
}
return 0;
}