-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1441 Build an array with stack operations.c
More file actions
44 lines (37 loc) · 1.16 KB
/
Copy path1441 Build an array with stack operations.c
File metadata and controls
44 lines (37 loc) · 1.16 KB
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
#define TARGET_LEN 101
int target_hash_table[TARGET_LEN] = {0};
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
char ** buildArray(int* target, int targetSize, int n, int* returnSize)
{
memset(target_hash_table, 0x00, sizeof(target_hash_table));
int i=1;
int max_num = target[targetSize - 1];
char ** ret_arr = (char **)malloc(sizeof(char *)*(2*n));
int ret_arr_index = 0;
for(i=0; i<targetSize; i++)
{
target_hash_table[target[i]] = 1;
}
for(i=1; i<=max_num; i++)
{
if(target_hash_table[i] == 1)
{
char * str_arr = (char *)malloc(sizeof(char) * 5);
ret_arr[ret_arr_index++] = str_arr;
sprintf(str_arr, "Push");
}
else
{
char * str_arr = (char *)malloc(sizeof(char) * 5);
ret_arr[ret_arr_index++] = str_arr;
sprintf(str_arr, "Push");
str_arr = (char *)malloc(sizeof(char) * 4);
ret_arr[ret_arr_index++] = str_arr;
sprintf(str_arr, "Pop");
}
}
*returnSize = ret_arr_index;
return ret_arr;
}