-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDfs.java
More file actions
36 lines (30 loc) · 773 Bytes
/
Dfs.java
File metadata and controls
36 lines (30 loc) · 773 Bytes
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
public class Dfs {
Node root;
public void DFS(Node root) {
if (root == null) {
return;
}
DFS(root.lt);
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);
}
public static class Node {
int data;
Node lt, rt;
public Node(int data) {
this.data = data;
lt = rt = null;
}
}
}