LAB 12 Data Structure Nadine ElHaddad S22107736 class Node int data Node left right public Node int item data item left right null class BinarySearchTree Node root public BinarySearchTree root null void insert int data root insertRec root data Node insertRec Node root int data if root null root new Node data return root if data root data root left insertRec root left data else if data root data root right insertRec root right data return root void inorderTraversal Node node if node null inorderTraversal node left System out print node data inorderTraversal node right int findMax if root null return Integer MIN VALUE Node current root while current right null current current right return current data public class Main public static void main String args BinarySearchTree bst new BinarySearchTree bst insert 5 bst insert 10 bst insert 20 bst insert 13 bst insert 15 bst insert 27 System out println Binary Search Tree Inorder Traversal bst inorderTraversal bst root System out println int maxValue bst findMax System out println Maximum value in the BST maxValue
View Full Document