There are two classes in the repository, the AVLTree.java
& AVLTreeTest.java
classes. AVLTree.java
contains the implementation for an AVL tree that uses a generic type for the key. The AVLTreeTest.java
is a testing class which tests the various methods in the AVLTree.java
file and prints out the results to the terminal.
The following methods are in the AVLTree.java
class:
void preOrder(AVLTreeNode<T> tree)
- prints a preorder traversal of the tree to the terminal from the specified nodevoid inOrder(AVLTreeNode<T> tree)
- prints an in-order traversal of the tree to the terminal from the specified nodevoid postOrder(AVLTreeeNode<T> tree)
- prints a post-order traversal of the tree to the terminal from the specified nodeAVLTreeNode<T> minimum(AVLTreeNode<T> tree)
- finds the smallest node of the AVL tree from the specified rootAVLTreeNode<T> maximum(AVLTreeNode<T> tree)
- finds the largest node of the AVL tree from the specified rootAVLTreeNode<T> insert(AVLTreeNode<T> tree, T key)
- inserts an element into the tree with given key and returns the root nodeAVLTreeNode<T> remove(AVLTreeNode<T> tree, AVLTreeNode<T> z)
- deletes the node (z), and then returns the root node
The AVLTreeTest.java
prints the following operations to the terminal in this order:
- Input the sequence
- Print out preOrder traversal
- Print out inOrder traversal
- Print out postOrder traversal
- Print out the height of the tree
- Print the smallest node of the tree
- Print the largest node of the tree
- Print the details of the tree
- Delete one node
- Print the height of the tree after the deletion
- Print out inOrder traversal after the deletion
- Print the details of the tree again
- Add one node
- Print out preOrder traversal after the addition