package SwordOffer;
import java.util.Stack;
public class lab31middium {
public static void main(String[] args){
lab31middium out = new lab31middium();
int [] push ={1,2,3,4,5};
int [] pop = {4,5,3,2,1};
System.out.println(out.validateStackSequences(push,pop));
}
public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stack=new Stack();
int pushLength=pushed.length;
int popLength=popped.length;
int i;
int j=0;
for(i=0;i<pushLength;i++){
stack.push(pushed[i]);
while(!stack.isEmpty()&&stack.peek().equals(popped[j])){
stack.pop();
j++;
}
}
return stack.isEmpty();
}
}