The AVLTree class represents a linked-memory AVL Tree.
More...
#include "avltree.h"
template<class K, class V>
class AVLTree< K, V >
The AVLTree class represents a linked-memory AVL Tree.
- Template Parameters
-
K | the type of key stored in the tree |
V | the type of value stored in the tree |
◆ AVLTree() [1/2]
template<class K , class V >
Constructor to create an empty tree.
◆ AVLTree() [2/2]
template<class K , class V >
Copy constructor.
- Parameters
-
◆ ~AVLTree()
template<class K , class V >
Destructor; frees all nodes associated with this tree.
◆ operator=()
template<class K , class V >
Assignment operator.
- Parameters
-
- Returns
- A reference to the current tree
◆ clear() [1/2]
template<class K , class V >
Frees all nodes associated with this tree and sets it to be empty.
◆ insert() [1/2]
template<class K , class V >
void AVLTree< K, V >::insert |
( |
const K & |
key, |
|
|
const V & |
value |
|
) |
| |
Inserts a key and value into the AVLTree.
- Parameters
-
key | The key to insert |
value | The value associated with the key |
◆ remove() [1/2]
template<class K , class V >
void AVLTree< K, V >::remove |
( |
const K & |
key | ) |
|
Removes a key from the AVLTree.
The key is assumed to exist in the tree.
- Parameters
-
◆ find() [1/2]
template<class K , class V >
V AVLTree< K, V >::find |
( |
const K & |
key | ) |
const |
Finds an element in the AVL tree.
- Parameters
-
key | The element to search for |
- Returns
- The value stored for that key
◆ print()
template<class K , class V >
void AVLTree< K, V >::print |
( |
ostream & |
out = cout | ) |
const |
Prints the AVLTree to a stream.
- Parameters
-
out | The stream to print to (default is stdout) |
◆ setOutput()
template<class K , class V >
void AVLTree< K, V >::setOutput |
( |
ostream & |
newOut | ) |
|
This function is used for grading.
- Parameters
-
newOut | The stream to print to |
◆ insert() [2/2]
template<class K , class V >
void AVLTree< K, V >::insert |
( |
Node *& |
node, |
|
|
const K & |
key, |
|
|
const V & |
value |
|
) |
| |
|
private |
Private helper function for the public insert function.
- Parameters
-
node | The current node in the recursion |
key | The key to insert |
value | The value associated with the key |
◆ remove() [2/2]
template<class K , class V >
void AVLTree< K, V >::remove |
( |
Node *& |
node, |
|
|
const K & |
key |
|
) |
| |
|
private |
Private helper function for the public remove function.
- Parameters
-
node | The current node in the recursion |
key | The key to remove |
◆ find() [2/2]
template<class K , class V >
V AVLTree< K, V >::find |
( |
Node * |
node, |
|
|
const K & |
key |
|
) |
| const |
|
private |
Finds a value (by key) in the AVL tree.
- Parameters
-
node | The node to search from (current subroot) |
key | The key to search for |
- Returns
- The value stored for that key
◆ rotateRight()
template<class K , class V >
Rotate the tree right (there is an imbalance on the left side).
- Parameters
-
◆ rotateLeft()
template<class K , class V >
Rotates the tree left (there is an imbalance on the right side).
- Parameters
-
◆ rotateRightLeft()
template<class K , class V >
A right-left rotation.
This function should simply call rotateRight and rotateLeft.
- Parameters
-
◆ rotateLeftRight()
template<class K , class V >
A left-right rotation.
This function should simply call rotateLeft and rotateRight.
- Parameters
-
◆ rebalance()
template<class K , class V >
Rebalance a node by performing rotations.
You can assume that node->left and node->right are both balanced. Even if no rotations are required, you should update the node's height.
- Parameters
-
◆ heightOrNeg1()
template<class K , class V >
int AVLTree< K, V >::heightOrNeg1 |
( |
const Node * |
node | ) |
const |
|
private |
- Parameters
-
node | The node's height to check |
- Returns
- The height of the node if it's non-
NULL
or -1 if it is NULL
◆ swap()
template<class K , class V >
Swap the keys and values of two nodes.
- Parameters
-
first | The first node to swap |
second | The node to swap with |
◆ copy()
template<class K , class V >
◆ clear() [2/2]
template<class K , class V >
Private helper function for clear that clears beneath the parameter node.
- Parameters
-
subRoot | The current node in the recursion |
◆ root
template<class K , class V >
◆ _out
template<class K , class V >
This variable is used for grading.
The documentation for this class was generated from the following files: