#include <the iostream> #include <string.h> #include <algorithm> #include <the cmath> #include <stdio.h> / * Title: Enter two integers sequences, a first sequence represented pressed into the stack order , the order of the second pop-up sequence represented stack. The first stack may determine whether a pop-up manner in the second sequence. * / / * Ideas: setting an auxiliary stack 2 traversal sequence. If traversed to the top element the same sequence element 2, then pop the stack, the next element traversed; if the sequence of elements traversed to the top element of the 2 different or stack is empty, one sequence will be pushed onto the stack until the identical, or all of the sequence 1 is pushed onto the stack. * / #Include <Vector> #include <Stack> the using namespace STD; BOOL IsPopOrder (Vector <int> pushV, Vector <int> popV) { int popVSize popV.size = (); int pushVSize pushV.size = (); IF (popVSize = pushVSize!) return to false; Stack <int> myStack; int pushVIndex = 0; for(int popVIndex = 0; popVIndex < popVSize; popVIndex++){ if(!myStack.empty() && myStack.top() == popV[popVIndex]){ myStack.pop(); }else{ while(pushVIndex < pushVSize && pushV[pushVIndex] != popV[popVIndex]){ myStack.push(pushV[pushVIndex]); pushVIndex++; } if(pushV[pushVIndex] != popV[popVIndex]){ return false; }else{ pushVIndex++; } } } return true; } int main(){ vector<int> pushV = {1,2,3,4,5}; vector<int> popV = {4,3,5,1,2}; cout << IsPopOrder (pushV, PONV) }