-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Section7-9. Tree 말단노드까지의 가장 짧은 경로(DFS)
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package 인프런.Section07; | ||
|
||
public class 말단노드_최단거리_DFS { | ||
Node root; | ||
|
||
public int DFS(int L, Node root) { | ||
if(root.lt == null && root.rt == null) return L; | ||
else return Math.min(DFS(L+1, root.lt), DFS(L+1, root.rt)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
말단노드_최단거리_DFS tree = new 말단노드_최단거리_DFS(); | ||
|
||
tree.root = new Node(1); | ||
tree.root.lt = new Node(2); | ||
tree.root.rt = new Node(3); | ||
tree.root.lt.lt = new Node(4); | ||
tree.root.lt.rt = new Node(5); | ||
|
||
System.out.print(tree.DFS(0, tree.root)); | ||
} | ||
} |