#include <iostream>
#include <stack>
using namespace std;
bool StackPop(int *p1,int *p2,int length);
int main()
{
int p1[]={1,2,3,4,5};
int p2[]={4,5,3,3,1};
bool xx=StackPop(p1,p2,5);
system("pause");
return 0;
}
bool StackPop(int *p1,int *p2,int length)
{
int i=0;
int j=0;
stack<int> temp1;
stack<int> temp2;
while (1)
{
if (i<length)
{
temp1.push(p1[i]);
}
if (p1[i]==p2[j] && i<length && j<length)
{
temp1.pop();
i++;
j++;
}
else if(i<length && j<length)
{
i++;
}
else if(i==length)
{
for (int k=j;k<length;k++)
{
if (p2[j]==temp1.top())
{
temp1.pop();
j++;
}
else
{
return false;
}
}
return true;
}
}
}