char ** buildArray(int* target
, int targetSize
, int n
, int* returnSize
){
char **res
= NULL;
int i
, j
;
res
= (char **)malloc(sizeof(char *) * n
* 2);
if (res
== NULL) {
return NULL;
}
memset(res
, 0, sizeof(char *) * n
* 2);
for (i
= 0; i
< n
* 2; i
++) {
res
[i
] = malloc(sizeof(char) * 5);
if (res
[i
] == NULL) {
return NULL;
}
memset(res
[i
], 0 , sizeof(char) * 5);
}
j
= 1;
*returnSize
= 0;
for (i
= 0; i
< targetSize
;) {
if (target
[i
] == j
) {
strcpy(res
[(*returnSize
)++], "Push");
i
++;
} else {
strcpy(res
[(*returnSize
)++], "Push");
strcpy(res
[(*returnSize
)++], "Pop");
}
j
++;
}
return res
;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-49232.html