-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompleteNodes.java
More file actions
36 lines (31 loc) · 1.06 KB
/
CompleteNodes.java
File metadata and controls
36 lines (31 loc) · 1.06 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
/* A program to find the all complete nodes in a given binary tree
* @ Author: Maricel Vicente
*/
public class CompleteNodes {
/* Traverses given tree in Inorder fashion and
* prints all nodes that have both children as non-empty.
*
*/
public static void findCompleteNode(Node root)
{
if (root != null)
{
findCompleteNode(root.left);
if (root.right != null && root.left != null)
System.out.print(root.data+" ");
findCompleteNode(root.right);
}
}
public static void main(String args[]) {
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.right.left = new Node(5);
root.right.right = new Node(6);
root.right.left.right = new Node(7);
root.right.right.right = new Node(8);
root.right.left.right.left = new Node(9);
findCompleteNode(root); // correct output is 1 and 3
}
}