bool isPopOrder(const int * pPush,const int * pPop, int nLength){
bool res = false;
if (pPush != nullptr && pPop != nullptr && nLength > 0){
const int * pNextPush = pPush;
const int * pNextPop = pPop;
stack<int> stackData;
while(pNextPop - pPop < nLength) {
while(stackData.empty() || stackData.top() != *pNextPop) {
if(pNextPop - pPop == nLength)
break;
stackData.push(*pNextPush);
pNextPush++;
}
if(stackData.top() != *pNextPop)
break;
stackData.pop();
pNextPop++;
}
if(stackData.empty() && pNextPop - pPop == nLength)
res = true;
}
return res;
}
网友评论