Bridges-C++ 3.5.0-dev1
Bridges(C++ API)
Loading...
Searching...
No Matches
BinTreeElement.h
Go to the documentation of this file.
1#ifndef BT_ELEMENT_H
2#define BT_ELEMENT_H
3
4#include "TreeElement.h" //string, using std
5
6namespace bridges {
7 namespace datastructure {
23 template <typename E>
24 class BinTreeElement : public TreeElement<E> {
25 private:
26 int leftPos = 0, rightPos = 1;
27 public:
39 const string& lab = string()) : TreeElement<E>(e, lab) {
40 this->addChild(l);
41 this->addChild(r);
42 }
43
52 BinTreeElement(const E& e = E(), const string& lab = string())
53 : BinTreeElement(nullptr, nullptr, e, lab) {
54 }
55
59 virtual const string getDStype() const override {
60 return "BinaryTree";
61 }
62
68 return static_cast<BinTreeElement*>(this->getChild(leftPos));
69 }
70
75 virtual const BinTreeElement* getLeft() const {
76 return static_cast<const BinTreeElement*>(this->getChild(leftPos));
77 }
78
85 this->setChild(leftPos, l);
86 }
87
93 return static_cast<BinTreeElement*>(this->getChild(rightPos));
94 }
95
100 virtual const BinTreeElement* getRight() const {
101 return static_cast<const BinTreeElement*>(this->getChild(rightPos));
102 }
103
110 this->setChild(rightPos, r);
111 }
112 }; //end of BinTreeElement class
113 }
114}//end of bridges namespace
115#endif
This class can be used to create binary tree elements, derived from TreeElement.
Definition BinTreeElement.h:24
BinTreeElement(const E &e=E(), const string &lab=string())
Definition BinTreeElement.h:52
virtual const BinTreeElement * getLeft() const
Definition BinTreeElement.h:75
void setLeft(BinTreeElement *l)
Definition BinTreeElement.h:84
virtual BinTreeElement * getRight()
Definition BinTreeElement.h:92
void setRight(BinTreeElement *r)
Definition BinTreeElement.h:109
BinTreeElement(BinTreeElement *l, BinTreeElement *r, const E &e=E(), const string &lab=string())
Definition BinTreeElement.h:38
virtual const BinTreeElement * getRight() const
Definition BinTreeElement.h:100
virtual BinTreeElement * getLeft()
Definition BinTreeElement.h:67
virtual const string getDStype() const override
Definition BinTreeElement.h:59
This class can be used to create tree elements, derived from Element.
Definition TreeElement.h:24
TreeElement * getChild(const int &n)
Gets the nth child of this node.
Definition TreeElement.h:73
void addChild(TreeElement *child)
Adds a child to children.
Definition TreeElement.h:94
void setChild(const size_t &index, TreeElement *kid)
Sets child at index to "kid".
Definition TreeElement.h:108
Support for drawing Bar charts.
Definition alltypes.h:4