public class BTNode { public int info; public BTNode rlink; public BTNode llink; public BTNode(BTNode rlink, int info, BTNode llink) { this.rlink = rlink; this.info = info; this.llink = llink; } } import java.util.*; public class BTClass { BTNode root; public BTClass() { root = null; } public BTClass(BTNode root) { this.root = root; } public boolean isEmpty() { if(root != null) { return false; } else { return true; } } // inOrder public void inOrderTraversal(BTNode root) { if(root != null) { inOrderTraversal(root.llink); System.out.print(" " + root.info); inOrderTraversal(root.rlink); } } // preOrder public void preOrderTraversal(BTNode root) { if(root != null) { System.out.print(" " + root.info); preOrderTraversal(root.llink); preOrderTraversal(root.rlink); } } // postOrder public void postOrderTraversal(BTNode root) { if(root != null) { postOrderTraversal(root.llink); postOrderTraversal(root.rlink); System.out.print(" " + root.info); } } // height public int height(BTNode height) { if(root == null) { return 0; } else { return 1 + Math.max(height(root.llink), height(root.rlink)); } } // nodeCount public int nodeCount(BTNode root) { if (root == null) { return 0; } else { return nodeCount(root.llink) + nodeCount(root.rlink); } } } import java.util.Scanner; public class testBT_Gonzaga { static Scanner s = new Scanner(System.in); public static void main(String[] args) { // instantiate BTClass btc = new BTClass(); while(true) { System.out.println(" --- MENU DRIVEN OPERATIONS --- "); System.out.println("1 - In Order Traversal "); System.out.println("2 - Pre Order Traversal "); System.out.println("3 - Post Order Traversal "); System.out.println("4 - Find tree height"); System.out.println("5 - Find node count"); System.out.println("0 - Program Exit"); int choice = s.nextInt(); switch(choice) { case 0: System.out.println("Exiting Program"); System.out.println(); System.exit(1); break; case 1: btc.inOrderTraversal(); System.out.println(); break; case 2: btc.preOrderTraversal(); System.out.println(); break; case 3: btc.postOrderTraversal(); System.out.println(); break; case 4: btc.height(); System.out.println(); break; case 5: btc.nodeCount(); System.out.println(); break; } } } }