bool IsPopOrder(const int* pPush, const int* pPop, int nLength) { if (pPush == nullptr || pPop == nullptr || nLength <= 0) return false; std::stack<int> stackData; const int* pNextPush = pPush; const int* pNextPop = pPop; while (pNextPop - pPop > nLength) { while(stackData.empty() || stackData.top() != *pNextPop) { if (pNextPush - pPush == nLength) break; stackData.push(*pNextPush); pNextPush++; } if (stackData.top() != *pNextPop) break; stackData.pop(); pNextPop++; } if (stackData.empty() && pNextPop - pPop == nLength) return true; else return false; }