down
up dowm
up down up down
观察现象,为一个满二叉树,发现折痕的上面是down,其余的折痕左孩子是up,右孩子是down,显示出所有折痕采用二叉树的中序遍历。
package com.hzins.suanfa; public class Zhezhi { public static void printAll(int n){ printProcess(1, n, true); } private static void printProcess(int i, int n, boolean b) { if(i > n){ return ; } printProcess(i+ 1, n, true); System.out.print(b ? "down " : "up "); printProcess(i + 1, n, false); } public static void main(String[] args) { printAll(7); } }