Skip to content

Instantly share code, notes, and snippets.

@thmain
Created February 24, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/6cadcb7b2ab477f977c1 to your computer and use it in GitHub Desktop.
Save thmain/6cadcb7b2ab477f977c1 to your computer and use it in GitHub Desktop.
public class FullNodes {
public void FindFullNodes(Node root) {
// do the traversal and print all the nodes which has left and right
// child
if (root != null) {
FindFullNodes(root.left);
if (root.left != null && root.right != null) {
System.out.print(root.data + " ");
}
FindFullNodes(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.left.right = new Node(5);
root.left.left.right = new Node(8);
FullNodes f = new FullNodes();
System.out.print("Full Nodes are ");
f.FindFullNodes(root);
}
}
class Node {
int data;
Node left;
Node right;
public Node(int data) {
this.data = data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment