// BTPrintLeaves1 - print out each leaf of the tree public class BTPrintLeaves1 { public static void main(String[] args) { BTNode root; root = beginningTree(); root.preorderPrint(); System.out.println(); root.inorderPrint(); System.out.println(); root.postorderPrint(); root.print(0); printLeaves(root); } public static BTNode beginningTree() { BTNode root; BTNode child; root = new BTNode(14, null, null); child = new BTNode(17, null, null); root.setLeft(child); child.setLeft(new BTNode(9, null, null)); child.setRight(new BTNode(53, null, null)); child = child.getLeft(); child.setLeft(new BTNode(13, null, null)); child = new BTNode(11, null, null); root.setRight(child); child.setLeft(new BTNode(4, null, null)); child = child.getLeft(); child.setLeft(new BTNode(19, null, null)); child.setRight(new BTNode(7, null, null)); return root; } public static void printLeaves(BTNode t) { if (t != null) { if (t.isLeaf()) System.out.println(t.getData() + " "); else { printLeaves(t.getLeft()); printLeaves(t.getRight()); } } } }