40 #include <forward_list>
43 using std::forward_list;
71 virtual const char*
what()
const throw(){
81 template <
typename T =
char>
129 this->
_tag = other._key;
142 return &
this == &rhs;
151 return &
this != &rhs;
172 int heights[2] = {0,0};
176 heights[1] = 1 + child.height();
178 if(heights[0] < heights[1]){
180 heights[0] = heights[1];
197 std::cout <<
_tag << std::endl;
201 if(it->_tag != n_data){
220 while(it != it.end() and undone){
221 if(it->_tag == data and it->isLeaf()){
244 return element ==
_tag;
250 while(not here and not it.end()){
251 here = it.contains(element);
266 string desc = string(
_tag);
268 desc +=
", " + child.toString();
280 template <
typename T =
string>
319 return _root->contains(element);
326 return _root.height();
333 _root.append(element);
339 void remove(T element){
341 _root.remove(element);
352 return _root.toString();
Node< T > & operator=(Node< T > &other)
Definition: tree.hpp:125
void put(T element)
Definition: tree.hpp:332
void append(T n_data)
Definition: tree.hpp:190
Defines tree nodes.
Definition: tree.hpp:82
int height()
Definition: tree.hpp:165
forward_list< Node< T > > _children
children of the Node
Definition: tree.hpp:90
~Tree()
Definition: tree.hpp:310
Tree(T element)
Definition: tree.hpp:303
bool operator!=(const Node< T > &rhs)
Definition: tree.hpp:150
string toString()
Definition: tree.hpp:261
char * _cause
Definition: tree.hpp:51
exception class for trees
Definition: tree.hpp:49
Tree()
Definition: tree.hpp:289
T _tag
letter stored into Node, the tag
Definition: tree.hpp:88
bool contains(T element)
Definition: tree.hpp:242
Tree is a recursive structure using nodes.
Definition: tree.hpp:281
string toString()
Definition: tree.hpp:351
bool operator==(const Node< T > &rhs)
Definition: tree.hpp:140
virtual const char * what() const
Definition: tree.hpp:71
Node(T data)
Definition: tree.hpp:105
bool isLeaf()
Definition: tree.hpp:158
int _childNbr
Number of children.
Definition: tree.hpp:86
virtual ~TreeException()
Definition: tree.hpp:64
Node(const Node< T > &other)
Definition: tree.hpp:96
~Node()
Definition: tree.hpp:115
int height()
Definition: tree.hpp:325
T getTag()
Definition: tree.hpp:235
bool contains(T element)
Definition: tree.hpp:318
Node< T > _root
Definition: tree.hpp:284
TreeException(char *cause)
Definition: tree.hpp:57
Tree(const Tree< T > &other)
Definition: tree.hpp:295