Question: Design and write a complete test program to test if the AVLTree class in Listing 26.4 meets all requirements. Listing 1 public class TestAVLTree {
Design and write a complete test program to test if the AVLTree class in Listing 26.4 meets all requirements.
Listing
![1 public class TestAVLTree { public static void main(String[] args) { //](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2022/11/636a73787ed0a_760636a73786ea1b.jpg)
1 public class TestAVLTree { public static void main(String[] args) { // Create an AVL tree AVLTree tree = new AVLTree (new Integer[]{25, 20, 5}); System.out.print("After inserting 25, 20, 5:"); printTree (tree); 3 4 8 tree.insert(34); tree.insert(50); System.out.print(" After inserting 34, 50:"); printTree(tree); 10 11 12 13 14 tree.insert(30); System.out.print(" After inserting 30"); printTree(tree); 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 tree.insert(10); System.out.print(" After inserting 10"); printTree(tree); tree.delete(34); tree.delete(30); tree.delete(50); System.out.print(" After removing 34, 30, 50:"); printTree(tree); tree.delete(5); System.out.print(" After removing 5:"); printTree(tree); System.out.print(" Traverse the elements in the tree: "); for (int e: tree) { System.out.print(e + " "); 34 35 36 37 38 public static void printTree(BST tree) { // Traverse tree System.out.print(" Inorder (sorted): "); tree.inorder); System.out.print(" Postorder: "); tree.postorder(); System.out.print(" Preorder: "); tree.preorder(); System.out.print(" The number of nodes is 39 40 41 41 43 44 45 + tree.getSize()); 46 nw3wmmmm
Step by Step Solution
3.34 Rating (169 Votes )
There are 3 Steps involved in it
Program Plan Create a TestAVLTree class refers to the text book for these fore classes BST clas AVLTree class AbstractTree and Tree class Create a printTreeMethod method to print AVL tree printTreeMet... View full answer
Get step-by-step solutions from verified subject matter experts
