-
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.
- Loading branch information
Showing
1 changed file
with
42 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,42 @@ | ||
package 인프런.Section07; | ||
|
||
import java.security.spec.RSAOtherPrimeInfo; | ||
|
||
class Node { | ||
int data; | ||
Node lt, rt; | ||
public Node(int val) { | ||
data = val; | ||
lt=rt=null; | ||
} | ||
} | ||
|
||
public class 이진트리순회_DFS { | ||
Node root; | ||
|
||
public void DFS(Node root) { | ||
if(root == null) return; | ||
else { | ||
//System.out.print(root.data + " "); //전위 순회 | ||
DFS(root.lt); | ||
//System.out.print(root.data + " "); //중위 순회 | ||
DFS(root.rt); | ||
//System.out.print(root.data + " "); //후위 순회 | ||
} | ||
} | ||
|
||
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); | ||
tree.root.rt.lt = new Node(6); | ||
tree.root.rt.rt = new Node(7); | ||
|
||
tree.DFS(tree.root); | ||
|
||
} | ||
} |