public static void stackOut(int[] nums,int inNum,int outNum,LinkedList<Integer> stack,ArrayList<Integer> output)
{
if(inNum==nums.length&&outNum==nums.length)
{
System.out.println(output);
num++;
}
else
{
LinkedList<Integer> stack1=(LinkedList<Integer>)stack.clone();
LinkedList<Integer> stack2=(LinkedList<Integer>)stack.clone();
if(inNum<nums.length)
{
stack1.push(nums[inNum]);
stackOut(nums,inNum+1,outNum,stack1,output);
stack1.pop();
}
ArrayList<Integer> output1=(ArrayList<Integer>)output.clone();
if(inNum>outNum)
{
output1.add(stack2.pop());
stackOut(nums,inNum,outNum+1,stack2,output1);
}
}
}
指定栈的进栈顺序,输出所有可能的出栈顺序
最新推荐文章于 2024-09-18 16:55:58 发布