-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathFindFullNodesInABinaryTree.java
More file actions
55 lines (42 loc) · 1.27 KB
/
Copy pathFindFullNodesInABinaryTree.java
File metadata and controls
55 lines (42 loc) · 1.27 KB
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
53
54
55
package trees;
//A Binary Tree Node
class Node{
int data;
Node left , right;
//Constructor of Node Class
Node(int data) {
this.data = data;
left = right = null ;
}
}
public class FindFullNodesInABinaryTree {
//Traverse given tree in In-order fashion & prints all nodes that have both children as non-empty
public static void findFullNode(Node root) {
if (root != null) {
findFullNode(root.left);
if(root.left != null && root.right != null)
System.out.println(root.data +" ");
findFullNode(root.right);
}
}
//Driver method
public static void main(String[] args) {
//Calling Node class by making an object of it (means by making a root node)
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
root.right.left = new Node(6);
root.right.right = new Node(7);
root.left.left.left= new Node(8);
root.right.left.left = new Node(9);
root.left.left.right = new Node(10);
root.left.right.left = new Node(11);
root.right.left.right = new Node(12);
root.left.right.right = new Node(13);
root.right.right.right = new Node(14);
//calling the find full nodes by passing values of or as root or root valuess in it
findFullNode(root);
}
}