#include <iostream>
#include <stack>
using namespace std;
bool Grial(int a[],int n,int b[],int m)
{
if(n!=m)return false;
stack<int> st;
int j = 0;
for(int i=0;i<n;i++)
{
st.push(a[i]);
while(st.empty()==false && st.top()==b[j])
{
j++;
st.pop();
}
}
if(st.empty()==true)return true;
else return false;
}
int main()
{
int a[] = {1,2,3,4,5};
int b[] = {3,2,1,4,5};
cout<<Grial(a,sizeof(a)/sizeof(int),b,sizeof(b)/sizeof(int))<<endl;
return 0;
}
笔试题:判断栈的push(),pop()序列是否正确
最新推荐文章于 2022-04-18 19:03:43 发布