-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavlTree.h
68 lines (56 loc) · 1.75 KB
/
avlTree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Alexis Francis & Jillian Hanson
// This is the avlTree.h, where we declare the classes Node and AVLTree
// and their respective helper methods/functions
#ifndef AVLTREE_H
#define AVLTREE_H
#include <iostream>
#include "dictionary.h"
template <typename K, typename V>
class Node {
public:
K key;
V value;
int height;
Node<K,V>* left;
Node<K,V>* right;
Node(K key, V value);
};
template <typename K, typename V>
class AVLTree: public Dictionary<K,V> {
protected:
Node<K,V> *root;
int size{};
public:
AVLTree();
virtual int getSize();
virtual bool isEmpty();
virtual void insert(K key, V value);
virtual void update(K key, V value);
virtual V get(K key);
virtual bool contains(K key);
virtual void remove(K key);
virtual vector<K> getKeys();
virtual vector<pair<K,V>> getItems();
vector<pair<K,V>> preOrder();
Node<K, V> * preorder_h(vector<pair<K,V>> &v, Node<K,V>*n);
vector<pair<K,V>> inOrder();
Node<K, V> * inorder_h(vector<pair<K,V>> &v, Node<K,V>*n);
vector<pair<K,V>> postOrder();
Node<K,V> * postorder_h(vector<pair<K,V>>&v, Node<K,V>*n);
void levelOrder();
pair<K,V> getMax();
pair<K,V> getMax_h(Node<K,V> *n);
//Node Stuff
Node<K,V>*getNode(K key, Node<K,V>*n);
Node<K,V> *rightRotate(Node<K,V>* a);
Node<K,V>* leftRotate(Node<K,V>* a);
int recalculateHeight(Node<K,V>* n);
int height(Node<K,V>* n);
Node<K,V>* insert_h(K key, V value, Node<K,V>* n);
Node<K,V>* remove_h(K key, Node<K,V>* n);
Node<K,V>* rebalance_LH(Node<K,V>* n);
Node<K,V>* rebalance_RH(Node<K,V>* n);
};
#include "avlTree_impl_protected.h"
#include "avlTree_impl_public.h"
#endif