Last active
May 6, 2017 12:57
-
-
Save lironsade/c4847995f63530c162f47c030df71481 to your computer and use it in GitHub Desktop.
Ex4 skeleton file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
/** | |
* Implements an AVL tree | |
*/ | |
class AvlTree implements Iterable<Integer> { | |
/* Constructors */ | |
/** | |
* The default constructor. | |
*/ | |
public AvlTree() { | |
} | |
/** | |
* A constructor that builds a new AVL tree containing all unique values in the input | |
* array. | |
* | |
* @param data the values to add to tree. | |
*/ | |
public AvlTree(int[] data) { | |
} | |
/** | |
* A copy constructor that creates a deep copy of the given AvlTree. The new tree | |
* contains all the values of the given tree, but not necessarily in the same structure. | |
* | |
* @param avlTree an AVL tree. | |
*/ | |
public AvlTree(AvlTree avlTree) { | |
} | |
/* Public Methods */ | |
/* | |
* Add a new node with the given key to the tree. | |
* | |
* @param newValue the value of the new node to add. | |
* @return true if the value to add is not already in the tree and it was successfully added, | |
* false otherwise. | |
*/ | |
public boolean add(int newValue) { | |
return false; | |
} | |
/** | |
* Check whether the tree contains the given input value. | |
* | |
* @param searchVal the value to search for. | |
* @return the depth of the node (0 for the root) with the given value if it was found in | |
* the tree, −1 otherwise. | |
*/ | |
public int contains(int searchVal) { | |
return 0; | |
} | |
/** | |
* Removes the node with the given value from the tree, if it exists. | |
* | |
* @param toDelete the value to remove from the tree. | |
* @return true if the given value was found and deleted, false otherwise. | |
*/ | |
public boolean delete(int toDelete) { | |
return false; | |
} | |
/** | |
* @return the number of nodes in the tree. | |
*/ | |
public int size() { | |
return 0; | |
} | |
/** | |
* @return an iterator for the Avl Tree. The returned iterator iterates over the tree nodes | |
* in an ascending order, and does NOT implement the remove() method. | |
*/ | |
public Iterator<Integer> iterator() { | |
return null; | |
} | |
/* Static Methods */ | |
/** | |
* Calculates the minimum number of nodes in an AVL tree of height h. | |
* | |
* @param h the height of the tree (a non−negative number) in question. | |
* @return the minimum number of nodes in an AVL tree of the given height. | |
*/ | |
public static int findMinNodes(int h) { | |
return 0; | |
} | |
/** | |
* Calculates the maximum number of nodes in an AVL tree of height h. | |
* | |
* @param h the height of the tree (a non−negative number) in question. | |
* @return the maximum number of nodes in an AVL tree of the given height. | |
*/ | |
public static int findMaxNodes(int h) { | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment