先来看说一下思路
接下来就是写代码了
int StackOrder(SeqStack* stack, char* input, char* output, int size_input, int size_output)
{if(stack == NULL || input == NULL || output == NULL){return 0;}int i_input = 0;int j_output = 0;SeqStackType value;for(; j_output < size_output; j_output++){SeqStackPush(stack, input[i_input]);SeqStackGetFront(stack, &value);while(value == input[j_output]){SeqStackPop(stack);SeqStackGetFront(stack, &value);j_output++;}i_input++;}if(j_output == size_output){return 1;}return 0;
}
测试用例
void TestOrder()
{SeqStack stack;SeqStackInit(&stack);char* input = "12345";char* output = "12345";int ret = StackOrder(&stack, input, output, strlen(input), strlen(output));printf("expected ret = 1, actual ret = %d\n", ret);
}int main()
{TestOrder();
}