-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path이진트리순회_DFS.java
42 lines (34 loc) · 1009 Bytes
/
이진트리순회_DFS.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}
}