Bridges-C++  3.1.1
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 
6 namespace 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  }
78  void setBalanceFactor(const int& bf) {
79  balFactor = bf;
80  }
85  virtual AVLTreeElement* getLeft() override {
86  return static_cast<AVLTreeElement*>(BSTElement<K, E>::getLeft());
87  }
93  virtual const AVLTreeElement* getLeft() const override {
94  return static_cast<const AVLTreeElement*>(BSTElement<K, E>::getLeft());
95  }
103  }
108  virtual AVLTreeElement* getRight() override {
109  return static_cast<AVLTreeElement*>(BSTElement<K, E>::getRight());
110  }
116  virtual const AVLTreeElement* getRight() const override {
117  return static_cast<const AVLTreeElement*>(BSTElement<K, E>::getRight());
118  }
126  }
127  private:
133  virtual const string getElementRepresentation() const override final {
135 
136  return json.insert (
137  json.size() - 1,
138  COMMA + QUOTE + "height" + QUOTE + COLON + to_string(height) +
139  COMMA + QUOTE + "balance_factor" + QUOTE + COLON +
140  to_string(balFactor)
141  );
142  }
143  }; //end of BSTElement class
144 
145  }
146 }//end of bridges namespace
147 #endif
This class can be used to create binary search tree elements, derived from BinTreeElement.
Definition: BSTElement.h:31
virtual const string getDStype() const override
Definition: AVLTreeElement.h:47
virtual const AVLTreeElement * getRight() const override
Definition: AVLTreeElement.h:116
virtual AVLTreeElement * getLeft() override
Definition: AVLTreeElement.h:85
virtual BSTElement * getRight() override
Definition: BSTElement.h:111
const string COLON
Definition: DataStructure.h:51
void setLeft(BSTElement *l)
Definition: BSTElement.h:104
virtual const AVLTreeElement * getLeft() const override
Definition: AVLTreeElement.h:93
int getHeight() const
Definition: AVLTreeElement.h:54
AVLTreeElement(const K &k, const E &val=E(), const string &lab=string())
Definition: AVLTreeElement.h:40
This class can be used to create avl tree elements, derived from BSTElement.
Definition: AVLTreeElement.h:26
void setLeft(AVLTreeElement *l)
Definition: AVLTreeElement.h:101
virtual BSTElement * getLeft() override
Definition: BSTElement.h:88
virtual AVLTreeElement * getRight() override
Definition: AVLTreeElement.h:108
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
void setHeight(const int &h)
Definition: AVLTreeElement.h:62
void setRight(AVLTreeElement *r)
Definition: AVLTreeElement.h:124
void setBalanceFactor(const int &bf)
Definition: AVLTreeElement.h:78
int getBalanceFactor() const
Definition: AVLTreeElement.h:69
virtual const string getElementRepresentation() const override
Definition: BSTElement.h:134
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
void setRight(BSTElement *r)
Definition: BSTElement.h:127