Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
AVLTreeElement.h
Go to the documentation of this file.
1#ifndef AVL_ELEMENT_H
2#define AVL_ELEMENT_H
3
4#include "BSTElement.h" //string, sstream, using std
5
6namespace bridges {
7 namespace datastructure {
25 template <typename K, typename E>
26 class AVLTreeElement : public BSTElement<K, E> {
27 private:
28 // The height and balance factor values
29 int height = 0, balFactor = 0;
30 public:
40 AVLTreeElement(const K& k, const E& val = E(), const string& lab = string())
41 : BSTElement<K, E>(k, nullptr, nullptr, val, lab) {}
42
47 virtual const string getDStype() const override {
48 return "AVLTree";
49 }
54 int getHeight() const {
55 return height;
56 }
62 void setHeight(const int& h) {
63 height = h;
64 }
69 int getBalanceFactor() const {
70 return balFactor;
71 }
77 void setBalanceFactor(const int& bf) {
78 balFactor = bf;
79 }
84 virtual AVLTreeElement* getLeft() override {
85 return static_cast<AVLTreeElement*>(BSTElement<K, E>::getLeft());
86 }
92 virtual const AVLTreeElement* getLeft() const override {
93 return static_cast<const AVLTreeElement*>(BSTElement<K, E>::getLeft());
94 }
102 }
107 virtual AVLTreeElement* getRight() override {
108 return static_cast<AVLTreeElement*>(BSTElement<K, E>::getRight());
109 }
115 virtual const AVLTreeElement* getRight() const override {
116 return static_cast<const AVLTreeElement*>(BSTElement<K, E>::getRight());
117 }
125 }
126 private:
132 virtual const string getElementRepresentation() const override final {
134
135 return json.insert (
136 json.size() - 1,
137 COMMA + QUOTE + "height" + QUOTE + COLON + to_string(height) +
138 COMMA + QUOTE + "balance_factor" + QUOTE + COLON +
139 to_string(balFactor)
140 );
141 }
142 }; //end of BSTElement class
143
144 }
145}//end of bridges namespace
146#endif
This class can be used to create avl tree elements, derived from BSTElement.
Definition: AVLTreeElement.h:26
virtual AVLTreeElement * getLeft() override
Definition: AVLTreeElement.h:84
void setBalanceFactor(const int &bf)
Definition: AVLTreeElement.h:77
virtual const AVLTreeElement * getLeft() const override
Definition: AVLTreeElement.h:92
int getHeight() const
Definition: AVLTreeElement.h:54
AVLTreeElement(const K &k, const E &val=E(), const string &lab=string())
Definition: AVLTreeElement.h:40
void setRight(AVLTreeElement *r)
Definition: AVLTreeElement.h:123
virtual const AVLTreeElement * getRight() const override
Definition: AVLTreeElement.h:115
virtual const string getDStype() const override
Definition: AVLTreeElement.h:47
virtual AVLTreeElement * getRight() override
Definition: AVLTreeElement.h:107
int getBalanceFactor() const
Definition: AVLTreeElement.h:69
void setHeight(const int &h)
Definition: AVLTreeElement.h:62
void setLeft(AVLTreeElement *l)
Definition: AVLTreeElement.h:100
This class can be used to create binary search tree elements, derived from BinTreeElement.
Definition: BSTElement.h:30
void setLeft(BSTElement *l)
Definition: BSTElement.h:103
virtual const string getElementRepresentation() const override
Definition: BSTElement.h:133
void setRight(BSTElement *r)
Definition: BSTElement.h:126
virtual BSTElement * getRight() override
Definition: BSTElement.h:110
virtual BSTElement * getLeft() override
Definition: BSTElement.h:87
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string COMMA
Definition: DataStructure.h:51
const string QUOTE
Definition: DataStructure.h:50