标签:scribe stack nbsp blog tac for class pop describe
package com.algorithm04; import java.util.Stack; public class Algorithm31 { public static boolean IsPopOrder(int [] pushA,int [] popA) { Stack<Integer> stack = new Stack<Integer>(); int i , j ; j = 0; if(pushA.length==0 || popA.length == 0 || pushA.length!=popA.length){ return false; } for(i = 0 ; i< pushA.length ; i++){ stack.push(pushA[i]); while(j < popA.length &&stack.peek()==popA[j]){ stack.pop(); j++; } } return stack.size()==0?true:false; } public static void main(String[] args) { int [] pushA = {1,2,3,4,5}; int [] popA = {4,5,3,2,1}; System.err.println(IsPopOrder(pushA, popA)); } }
标签:scribe stack nbsp blog tac for class pop describe
原文地址:http://www.cnblogs.com/CloudStrife/p/7348426.html