forked from ismajl-ramadani/AVLTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAVLTree.h
34 lines (26 loc) · 771 Bytes
/
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
#ifndef AVLTree_H_
#define AVLTree_H_
#include "BinarySearchTree.h"
#include <vector>
#include <iostream> //for NULL bad_alloc and vector
using std::vector;
using std::bad_alloc;
//AVL of integer objects
class AVLTree : public BinarySearchTree
{
public:
bool add(const ItemType& newData);
bool remove(const ItemType& data);
private:
void balancePath(Node* &node);
//rotation methods
void leftRotate(Node* &nodeA, Node* &parentOfA);
void rightRotate(Node* &nodeA, Node* &parentOfA);
//helper methods
void updateHeight(Node *node);
int balanceFactor(Node* subtreePtr);
/*Returns a path from the root leading to specified element*/
public: std::vector<Node*>* getPath(int item) const;
Node* createNewNodeWithItem(int item);
};
#endif