之前的写法比较屌丝,从同事那来个比较高大上的,让脑袋转转
package ext.pack.test;
import java.util.Stack;
public class HelloWorld extends TestInterface {
public static void printStack(Stack stack) {
System.out.println("STACK:BEGIN");
int STACK_SIZE = stack.size();
for (int i = STACK_SIZE; i > 0; i--) {
T[] objs = stack.get(i - 1);
for (T obj : objs) {
System.out.print(obj + ",");
}
System.out.println();
}
System.out.println("STACK:END");
}
public static void c2(int n) {
long s = 0, rt = 0;
int branch = 0;
Stack
Log分析:
branch=0,STACK:BEGIN
0,0,2,
0,0,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=0
POPUP Branch=0 s=0 n=2 rt=0
STACK:BEGIN
0,0,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,0,2,
0,0,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=1 s=0 n=2 rt=1
STACK:BEGIN
0,0,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=0 s=0 n=4 rt=1
STACK:BEGIN
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=0 s=0 n=3 rt=1
STACK:BEGIN
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,1,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,2,
1,1,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=0
POPUP Branch=0 s=0 n=2 rt=0
STACK:BEGIN
1,1,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,0,2,
1,1,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=1 s=0 n=2 rt=1
STACK:BEGIN
1,1,3,
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=1 n=3 rt=1
STACK:BEGIN
1,1,4,
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=1 n=4 rt=2
STACK:BEGIN
0,0,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=0 s=0 n=6 rt=3
STACK:BEGIN
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=0 s=0 n=3 rt=1
STACK:BEGIN
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,1,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,2,
1,1,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=0
POPUP Branch=0 s=0 n=2 rt=0
STACK:BEGIN
1,1,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,0,2,
1,1,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=1 s=0 n=2 rt=1
STACK:BEGIN
1,1,3,
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=1 n=3 rt=1
STACK:BEGIN
0,0,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=0 s=0 n=5 rt=2
STACK:BEGIN
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,2,
0,0,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=0
POPUP Branch=0 s=0 n=2 rt=0
STACK:BEGIN
0,0,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,0,2,
0,0,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=1 s=0 n=2 rt=1
STACK:BEGIN
0,0,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=0 s=0 n=4 rt=1
STACK:BEGIN
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=0 s=0 n=3 rt=1
STACK:BEGIN
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,1,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=0,STACK:BEGIN
0,0,2,
1,1,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=0
POPUP Branch=0 s=0 n=2 rt=0
STACK:BEGIN
1,1,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
branch=1,STACK:BEGIN
1,0,2,
1,1,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Print $$n<2, n=1
POPUP Branch=1 s=0 n=2 rt=1
STACK:BEGIN
1,1,3,
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=1 n=3 rt=1
STACK:BEGIN
1,1,4,
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=1 n=4 rt=2
STACK:BEGIN
1,2,5,
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=2 n=5 rt=3
STACK:BEGIN
1,3,6,
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
POPUP Branch=1 s=3 n=6 rt=5
STACK:BEGIN
STACK:END
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
We have the previous Result!!
Result is :8