An inbound stack sequence is provided for a sequence stack. However, during the inbound stack, elements may be generated and the final sequence may appear.
The idea is what you think. I will not repeat it again. It is difficult to type and it is easy to read the code page. It will not be written.
Void init_queue (queue <int> & Q, const int A [], const int N) {for (unsigned I = 0; I <n; I ++) {q. push (A [I]) ;}} void check_stack_order (INT pushdata [], int checkdata [], int N) {queue <int> pushqueue; init_queue (pushqueue, pushdata, n); stack <int> tempstack; int I = 0; while (true) {If (! Tempstack. empty () & tempstack. top () = checkdata [I]) {tempstack. pop (); ++ I;} else {If (pushqueue. empty () {break;} tempstack. push (pushqueue. front (); pushqueue. pop () ;}}if (I = N) {cout <"Wright order! "<Endl;} else {cout <" wrong order! "<Endl ;}int main (void) {int pushdata [] = {1, 2, 4, 5}; // int check [] = {5, 1, 2, 4, 3}; int check [] = {2, 1, 4, 3, 5}; check_stack_order (pushdata, check, sizeof (pushdata)/sizeof (INT); Return 0 ;}