标签:
1 bool IsPopOrder(const int* pPush,const int* pPop,int nLength) 2 { 3 bool bPossible=false; 4 if(pPush!=NULL&&pPop!=NULL&&nLength>0) 5 { 6 const int* pNextPush=pPush; 7 const int* pNextPop=pPop; 8 std::stack<int> stackData; 9 10 while(pNextPop-pPop<nLength) 11 { 12 while(stackData.empty()||stackData.top()!=*pNextPop) 13 { 14 if(pNextPush-pPush==nLength) 15 break; 16 stackData.push(*pNextPush); 17 pNextPush++; 18 } 19 if(stackData.top()!=*pNextPop) 20 break; 21 22 stackData.pop(); 23 pNextPop++; 24 } 25 if(stackData.empty()&&pNextpop-pPop==nLength) 26 bPossible=true; 27 } 28 return bPossible; 29 }
标签:
原文地址:http://www.cnblogs.com/wxdjss/p/5604207.html