-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBTreeLevelNodes.java
More file actions
52 lines (40 loc) · 999 Bytes
/
BTreeLevelNodes.java
File metadata and controls
52 lines (40 loc) · 999 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
import java.util.*;
import java.lang.*;
class Node{
int data;
Node left;
Node right;
Node(int k){
data=k;
left=null;
right=null;
}
}
public class BTreeLevelNodes{
public static void traverse(Node root, int k){
if(root==null)
return;
if(k==0)
System.out.print(root.data+" ");
else{
traverse(root.left,k-1);
traverse(root.right,k-1);
}
}
public static void main(String args[]){
// 10
// 20 30
// 40 50 60 70
// 80
Node root = new Node(10);
root.left = new Node(20);
root.right = new Node(30);
root.left.left = new Node(40);
root.left.right = new Node(50);
root.right.left = new Node(60);
root.right.right = new Node(70);
root.left.right.left = new Node(80);
traverse(root,2);
}
}