aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2016-12-03 13:19:38 +0000
committerzedarider <ymherklotz@gmail.com>2016-12-03 13:19:38 +0000
commitaaf3a8e6af453b0db1ed7d5faef6367d7a613b3a (patch)
tree1157409020f13520994dd6643560b2b7be9adc04
parent5973d6a630ccf93e580ed01bd347c2ffa3fb7b39 (diff)
downloadBinaryTree-aaf3a8e6af453b0db1ed7d5faef6367d7a613b3a.tar.gz
BinaryTree-aaf3a8e6af453b0db1ed7d5faef6367d7a613b3a.zip
adding all files
-rwxr-xr-xbin/binary_tree_testbin28852 -> 28852 bytes
-rw-r--r--include/binary_tree.hpp56
2 files changed, 10 insertions, 46 deletions
diff --git a/bin/binary_tree_test b/bin/binary_tree_test
index 8d0ef45..242bd7c 100755
--- a/bin/binary_tree_test
+++ b/bin/binary_tree_test
Binary files differ
diff --git a/include/binary_tree.hpp b/include/binary_tree.hpp
index 1927a16..e0428f1 100644
--- a/include/binary_tree.hpp
+++ b/include/binary_tree.hpp
@@ -16,7 +16,8 @@ class Node {
friend BinaryTree<T>;
public:
// create an empty node with no next and only adding the item
- Node(const T& it) : item(it), next_left(NULL), next_right(NULL) {}
+ Node(const T& it, const T& height) : item(it), next_left(NULL),
+ next_right(NULL), height(height), depth(0), bf(0) {}
// create a new node with next nodes
Node(const T& it, Node<T>* n_left, Node<T> n_right)
@@ -57,47 +58,7 @@ public:
return out;
}
- // return information of the values from the node
- T get_item() {
- return item;
- }
-
- Node<T>* get_next_left() {
- return next_left;
- }
-
- Node<T>* get_next_right() {
- return next_right;
- }
-
- unsigned int get_height() {
- return height;
- }
-
- unsigned int get_depth() {
- return depth;
- }
-
- signed int get_bf() {
- return bf;
- }
protected:
- void set_item(T it) {
- item = it;
- }
-
- void set_next_left(Node<T> n_left) {
- next_left = n_left;
- }
-
- void set_next_right(Node<T>* n_right) {
- next_right = n_right;
- }
-
- void set_next(Node<T>* n_left, Node<T>* n_right) {
- set_next_left(n_left);
- set_next_right(n_right);
- }
private:
// item stored in the tree
T item;
@@ -127,7 +88,7 @@ public:
// adds an element to the tree
void push_back(const T& element) {
// create new node with element
- node_ptr new_node = new Node<T>(element);
+ node_ptr new_node = new Node<T>(element, tree_height);
if(root_node == NULL) {
root_node = new_node;
@@ -157,6 +118,13 @@ public:
}
}
+ void set_height_depth(node_ptr node) {
+ if(node != NULL) {
+ set_height_depth(node->next_left);
+ set_height_depth(node->next_right);
+ }
+ }
+
void delete_nodes(node_ptr node) {
if(node != NULL) {
this->delete_nodes(node->next_left);
@@ -177,10 +145,6 @@ public:
print_tree(node->next_right);
}
}
-
- Node<T> get_root() {
- return *root_node;
- }
private:
// root of the tree
node_ptr root_node;