标签:
class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { bool result=false; int n1=pushV.size(); int n2=popV.size(); if(!n1||!n2) return result; int push_index=0; int pop_index=0; stack<int> s; s.push(pushV[push_index++]); while(pop_index<n2) { while(s.top()!=popV[pop_index]&&push_index<n1) s.push(pushV[push_index++]); if(s.top()==popV[pop_index]) { s.pop(); pop_index++; } else break; } if(pop_index==n2) result=true; return result; } };
*不可以在堆栈为空时,使用s.top()函数,会发生未知!
*要注意边界条件!!
标签:
原文地址:http://www.cnblogs.com/summerkiki/p/5518859.html