Tree | insert public class Tree { public void insert(Node node, int value) { if (value < node.value) { if (node.left != null) { insert(node.left, value); } else { System.out.println(" Inserted to left"); node.left = new Node(value); } } else if (value > node.value) { if (node.right != null) { insert(node.right, value); } else { System.out.println(" Inserted to right "); node.right = new Node(value); } } }
Tree | Traverse In Order public void traverseInOrder(Node node) { if (node != null) { traverseInOrder(node.left); System.out.print(" " + node.value); traverseInOrder(node.right); } }
Tree | Traverse Pre Order public void traverseInOrder(Node node) { if (node != null) { System.out.print(" " + node.value); traverseInOrder(node.left); traverseInOrder(node.right); } }
Tree | Traverse Post Order public void traverseInOrder(Node node) { if (node != null) { traverseInOrder(node.left); traverseInOrder(node.right); System.out.print(" " + node.value); } }
Ph.D. [email protected] Fall 2021 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.