From 6a78267ec5c2c20d1095b0029ea096602339eaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E7=A8=8B=E4=BA=91?= Date: Tue, 8 Dec 2020 22:47:00 +0800 Subject: [PATCH] modify code structure --- .../Code02_SerializeAndReconstructTree.java | 2 +- src/class07_11/Code07_PaperFolding.java | 20 +++++++++++-------- .../Code01_IsCBT.java} | 4 ++-- .../Code02_IsBST.java} | 4 ++-- .../Code03_IsBalanced.java} | 4 ++-- .../Code04_IsFull.java} | 4 ++-- .../Code05_MaxSubBSTSize.java} | 4 ++-- .../Code06_MaxSubBSTHead.java} | 4 ++-- .../Code07_lowestAncestor.java | 2 +- .../Code08_MaxDistance.java | 2 +- .../Code09_MaxHappy.java | 2 +- 11 files changed, 28 insertions(+), 24 deletions(-) rename src/{class08/Code06_IsCBT.java => class08_12/Code01_IsCBT.java} (98%) rename src/{class08/Code03_IsBST.java => class08_12/Code02_IsBST.java} (98%) rename src/{class08/Code01_IsBalanced.java => class08_12/Code03_IsBalanced.java} (97%) rename src/{class08/Code02_IsFull.java => class08_12/Code04_IsFull.java} (97%) rename src/{class08/Code04_MaxSubBSTSize.java => class08_12/Code05_MaxSubBSTSize.java} (98%) rename src/{class08/Code05_MaxSubBSTHead.java => class08_12/Code06_MaxSubBSTHead.java} (98%) rename src/{class08 => class08_12}/Code07_lowestAncestor.java (99%) rename src/{class08 => class08_12}/Code08_MaxDistance.java (99%) rename src/{class08 => class08_12}/Code09_MaxHappy.java (99%) diff --git a/src/class07_11/Code02_SerializeAndReconstructTree.java b/src/class07_11/Code02_SerializeAndReconstructTree.java index 9ea02bb..af5e5de 100644 --- a/src/class07_11/Code02_SerializeAndReconstructTree.java +++ b/src/class07_11/Code02_SerializeAndReconstructTree.java @@ -129,7 +129,7 @@ public class Code02_SerializeAndReconstructTree { Queue queue = new LinkedList(); queue.add(head); while (!queue.isEmpty()) { - head = queue.poll(); + head = queue.poll(); // head 父 子 if (head.left != null) { ans.add(String.valueOf(head.left.value)); queue.add(head.left); diff --git a/src/class07_11/Code07_PaperFolding.java b/src/class07_11/Code07_PaperFolding.java index 7cd7230..0a2b72f 100644 --- a/src/class07_11/Code07_PaperFolding.java +++ b/src/class07_11/Code07_PaperFolding.java @@ -3,22 +3,26 @@ package class07_11; public class Code07_PaperFolding { public static void printAllFolds(int N) { - printProcess(1, N, true); + process(1, N, true); + System.out.println(); } - // 递归过程,来到了某一个节点, - // i是节点的层数,N一共的层数,down == true 凹 down == false 凸 - public static void printProcess(int i, int N, boolean down) { + // 当前你来了一个节点,脑海中想象的! + // 这个节点在第i层,一共有N层,N固定不变的 + // 这个节点如果是凹的话,down = T + // 这个节点如果是凸的话,down = F + // 函数的功能:中序打印以你想象的节点为头的整棵树! + public static void process(int i, int N, boolean down) { if (i > N) { return; } - printProcess(i + 1, N, true); - System.out.println(down ? "凹 " : "凸 "); - printProcess(i + 1, N, false); + process(i + 1, N, true); + System.out.print(down ? "凹 " : "凸 "); + process(i + 1, N, false); } public static void main(String[] args) { - int N = 3; + int N = 4; printAllFolds(N); } } diff --git a/src/class08/Code06_IsCBT.java b/src/class08_12/Code01_IsCBT.java similarity index 98% rename from src/class08/Code06_IsCBT.java rename to src/class08_12/Code01_IsCBT.java index a2aaf40..a5a153e 100644 --- a/src/class08/Code06_IsCBT.java +++ b/src/class08_12/Code01_IsCBT.java @@ -1,8 +1,8 @@ -package class08; +package class08_12; import java.util.LinkedList; -public class Code06_IsCBT { +public class Code01_IsCBT { public static class Node { public int value; diff --git a/src/class08/Code03_IsBST.java b/src/class08_12/Code02_IsBST.java similarity index 98% rename from src/class08/Code03_IsBST.java rename to src/class08_12/Code02_IsBST.java index a6a7922..199c188 100644 --- a/src/class08/Code03_IsBST.java +++ b/src/class08_12/Code02_IsBST.java @@ -1,8 +1,8 @@ -package class08; +package class08_12; import java.util.ArrayList; -public class Code03_IsBST { +public class Code02_IsBST { public static class Node { public int value; diff --git a/src/class08/Code01_IsBalanced.java b/src/class08_12/Code03_IsBalanced.java similarity index 97% rename from src/class08/Code01_IsBalanced.java rename to src/class08_12/Code03_IsBalanced.java index 38238c4..0eee9fd 100644 --- a/src/class08/Code01_IsBalanced.java +++ b/src/class08_12/Code03_IsBalanced.java @@ -1,6 +1,6 @@ -package class08; +package class08_12; -public class Code01_IsBalanced { +public class Code03_IsBalanced { public static class Node { public int value; diff --git a/src/class08/Code02_IsFull.java b/src/class08_12/Code04_IsFull.java similarity index 97% rename from src/class08/Code02_IsFull.java rename to src/class08_12/Code04_IsFull.java index 1512def..ef04e12 100644 --- a/src/class08/Code02_IsFull.java +++ b/src/class08_12/Code04_IsFull.java @@ -1,6 +1,6 @@ -package class08; +package class08_12; -public class Code02_IsFull { +public class Code04_IsFull { public static class Node { public int value; diff --git a/src/class08/Code04_MaxSubBSTSize.java b/src/class08_12/Code05_MaxSubBSTSize.java similarity index 98% rename from src/class08/Code04_MaxSubBSTSize.java rename to src/class08_12/Code05_MaxSubBSTSize.java index 2f4116c..d35e699 100644 --- a/src/class08/Code04_MaxSubBSTSize.java +++ b/src/class08_12/Code05_MaxSubBSTSize.java @@ -1,8 +1,8 @@ -package class08; +package class08_12; import java.util.ArrayList; -public class Code04_MaxSubBSTSize { +public class Code05_MaxSubBSTSize { public static class Node { public int value; diff --git a/src/class08/Code05_MaxSubBSTHead.java b/src/class08_12/Code06_MaxSubBSTHead.java similarity index 98% rename from src/class08/Code05_MaxSubBSTHead.java rename to src/class08_12/Code06_MaxSubBSTHead.java index b9fa1a4..abe7551 100644 --- a/src/class08/Code05_MaxSubBSTHead.java +++ b/src/class08_12/Code06_MaxSubBSTHead.java @@ -1,8 +1,8 @@ -package class08; +package class08_12; import java.util.ArrayList; -public class Code05_MaxSubBSTHead { +public class Code06_MaxSubBSTHead { public static class Node { public int value; diff --git a/src/class08/Code07_lowestAncestor.java b/src/class08_12/Code07_lowestAncestor.java similarity index 99% rename from src/class08/Code07_lowestAncestor.java rename to src/class08_12/Code07_lowestAncestor.java index 6a9affd..a39b301 100644 --- a/src/class08/Code07_lowestAncestor.java +++ b/src/class08_12/Code07_lowestAncestor.java @@ -1,4 +1,4 @@ -package class08; +package class08_12; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/class08/Code08_MaxDistance.java b/src/class08_12/Code08_MaxDistance.java similarity index 99% rename from src/class08/Code08_MaxDistance.java rename to src/class08_12/Code08_MaxDistance.java index 1fd6e95..930c1dc 100644 --- a/src/class08/Code08_MaxDistance.java +++ b/src/class08_12/Code08_MaxDistance.java @@ -1,4 +1,4 @@ -package class08; +package class08_12; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/class08/Code09_MaxHappy.java b/src/class08_12/Code09_MaxHappy.java similarity index 99% rename from src/class08/Code09_MaxHappy.java rename to src/class08_12/Code09_MaxHappy.java index 8e80e6e..b52851e 100644 --- a/src/class08/Code09_MaxHappy.java +++ b/src/class08_12/Code09_MaxHappy.java @@ -1,4 +1,4 @@ -package class08; +package class08_12; import java.util.ArrayList; import java.util.List;