You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
623 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package class032;
public class Code03_PaperFolding {
public static void printAllFolds(int N) {
process(1, N, true);
System.out.println();
}
// 假想中的当前节点在i层一共N层
// 假想中的当前节点凹还是凸down决定down = true 凹 down = false 凸
// 打印以假想节点为头的整棵树,中序打印
public static void process(int i, int N, boolean down) {
if (i > N) {
return;
}
process(i + 1, N, true);
System.out.print(down ? "凹 " : "凸 ");
process(i + 1, N, false);
}
public static void main(String[] args) {
int N = 4;
printAllFolds(N);
}
}