出栈合法性,第一个例子有问题,在i==4的时候会死在循环里,我不知道为啥

img


代码奉上:#include
#include
#include
#include
#include
using namespace std;
int n;
stack a;
deque b;
int main()
{
int n;
while(cin>>n&&n)
{
int k;
int i;
int t=n;
for(i=1; i<=n; i++)
{
cin>>k;
b.push_back(k);
}
int temp=0;
for(i=1; i<=n; i++)
{
if(a.size()==0||a.top()!=b.front()) a.push(i);
while(a.top()==b.front()&&a.size()>0&&b.size()>0)
{
a.pop();
b.pop_front();
}
}
if(temp==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

return 0;

}
为啥呀