/**
* 测试队列入栈和出栈顺序
* @author Administrator
*
*/
public class QueenTest {
public static boolean isPopOrder(int[] pushA,int[] popA) {
Stack<Integer> stack=new Stack<>();
int i=0;
for (Integer integer : pushA) {
stack.push(integer);
while (!stack.isEmpty()&&stack.peek()==popA[i]) {
stack.pop();
i++;
}
}
if (stack.isEmpty()) {
return true;
}
return false;
}
public static void main(String[] args) {
int[] pushA={1,2,3,4,5};
int[] pushB={3,5,4,2,1};
boolean b = QueenTest.isPopOrder(pushA, pushB);
System.out.println(b);
}
}
* 测试队列入栈和出栈顺序
* @author Administrator
*
*/
public class QueenTest {
public static boolean isPopOrder(int[] pushA,int[] popA) {
Stack<Integer> stack=new Stack<>();
int i=0;
for (Integer integer : pushA) {
stack.push(integer);
while (!stack.isEmpty()&&stack.peek()==popA[i]) {
stack.pop();
i++;
}
}
if (stack.isEmpty()) {
return true;
}
return false;
}
public static void main(String[] args) {
int[] pushA={1,2,3,4,5};
int[] pushB={3,5,4,2,1};
boolean b = QueenTest.isPopOrder(pushA, pushB);
System.out.println(b);
}
}