From 334755ad2b56ed723154289fbeee1afb24e779a9 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 9 Sep 2022 23:38:59 +0000 Subject: [PATCH] Documentation for 60fc753f7f6af47162ae53a89122828abfe10e7e --- d9/dde/classbinary__search__tree.html | 352 ++++++++--------- ...ructbinary__search__tree_1_1bst__node.html | 16 +- de/d33/binary__search__tree2_8cpp__incl.map | 2 +- de/d33/binary__search__tree2_8cpp__incl.md5 | 2 +- de/d33/binary__search__tree2_8cpp__incl.svg | 2 +- df/d42/binary__search__tree2_8cpp.html | 370 +++++++++--------- dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html | 2 +- files.html | 2 +- 8 files changed, 374 insertions(+), 374 deletions(-) diff --git a/d9/dde/classbinary__search__tree.html b/d9/dde/classbinary__search__tree.html index bcc41b371..80b2ab50a 100644 --- a/d9/dde/classbinary__search__tree.html +++ b/d9/dde/classbinary__search__tree.html @@ -225,12 +225,12 @@ template<class T >

Construct a new Binary Search Tree object.

-
246 {
-
247 root_ = nullptr;
-
248 size_ = 0;
-
249 }
-
std::size_t size_
Definition: binary_search_tree2.cpp:42
-
std::unique_ptr< bst_node > root_
Definition: binary_search_tree2.cpp:41
+
247 {
+
248 root_ = nullptr;
+
249 size_ = 0;
+
250 }
+
std::size_t size_
Definition: binary_search_tree2.cpp:43
+
std::unique_ptr< bst_node > root_
Definition: binary_search_tree2.cpp:42
@@ -282,20 +282,20 @@ template<class T >
Returns
true If the value was found in the BST.
false Otherwise.
-
176 {
-
177 if (!node) {
-
178 return false;
-
179 }
-
180
-
181 if (value < node->value) {
-
182 return contains(node->left, value);
-
183 } else if (value > node->value) {
-
184 return contains(node->right, value);
-
185 } else {
-
186 return true;
-
187 }
-
188 }
-
bool contains(std::unique_ptr< bst_node > &node, T value)
Recursive function to check if a value is in the BST.
Definition: binary_search_tree2.cpp:176
+
177 {
+
178 if (!node) {
+
179 return false;
+
180 }
+
181
+
182 if (value < node->value) {
+
183 return contains(node->left, value);
+
184 } else if (value > node->value) {
+
185 return contains(node->right, value);
+
186 } else {
+
187 return true;
+
188 }
+
189 }
+
bool contains(std::unique_ptr< bst_node > &node, T value)
Recursive function to check if a value is in the BST.
Definition: binary_search_tree2.cpp:177
Definition: avltree.cpp:13
Here is the call graph for this function:
@@ -342,7 +342,7 @@ template<class T >
Returns
true If value is in the BST.
false Otherwise.
-
288{ return contains(root_, value); }
+
289{ return contains(root_, value); }
Here is the call graph for this function:
@@ -399,16 +399,16 @@ template<class T >
Returns
true If the maximum value was successfully found.
false Otherwise.
-
52 {
-
53 if (!node) {
-
54 return false;
-
55 } else if (!node->right) {
-
56 ret_value = node->value;
-
57 return true;
-
58 }
-
59 return find_max(node->right, ret_value);
-
60 }
-
bool find_max(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the maximum value in the BST.
Definition: binary_search_tree2.cpp:52
+
53 {
+
54 if (!node) {
+
55 return false;
+
56 } else if (!node->right) {
+
57 ret_value = node->value;
+
58 return true;
+
59 }
+
60 return find_max(node->right, ret_value);
+
61 }
+
bool find_max(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the maximum value in the BST.
Definition: binary_search_tree2.cpp:53
Here is the call graph for this function:
@@ -454,7 +454,7 @@ template<class T >
Returns
true If maximum value was successfully found.
false Otherwise.
-
306{ return find_max(root_, ret_value); }
+
307{ return find_max(root_, ret_value); }
Here is the call graph for this function:
@@ -511,17 +511,17 @@ template<class T >
Returns
true If the minimum value was successfully found.
false Otherwise.
-
70 {
-
71 if (!node) {
-
72 return false;
-
73 } else if (!node->left) {
-
74 ret_value = node->value;
-
75 return true;
-
76 }
-
77
-
78 return find_min(node->left, ret_value);
-
79 }
-
bool find_min(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the minimum value in the BST.
Definition: binary_search_tree2.cpp:70
+
71 {
+
72 if (!node) {
+
73 return false;
+
74 } else if (!node->left) {
+
75 ret_value = node->value;
+
76 return true;
+
77 }
+
78
+
79 return find_min(node->left, ret_value);
+
80 }
+
bool find_min(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the minimum value in the BST.
Definition: binary_search_tree2.cpp:71
Here is the call graph for this function:
@@ -567,7 +567,7 @@ template<class T >
Returns
true If minimum value was successfully found.
false Otherwise.
-
297{ return find_min(root_, ret_value); }
+
298{ return find_min(root_, ret_value); }
Here is the call graph for this function:
@@ -604,13 +604,13 @@ template<class T >

Get all values of the BST in in-order order.

Returns
std::vector<T> List of values, sorted in in-order order.
-
320 {
- -
322 traverse_inorder([&](T node_value) { result.push_back(node_value); },
-
323 root_);
-
324 return result;
-
325 }
-
void traverse_inorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in in-order order.
Definition: binary_search_tree2.cpp:196
+
321 {
+ +
323 traverse_inorder([&](T node_value) { result.push_back(node_value); },
+
324 root_);
+
325 return result;
+
326 }
+
void traverse_inorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in in-order order.
Definition: binary_search_tree2.cpp:197
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76
@@ -649,13 +649,13 @@ template<class T >

Get all values of the BST in post-order order.

Returns
std::vector<T> List of values, sorted in post-order order.
-
344 {
- -
346 traverse_postorder([&](T node_value) { result.push_back(node_value); },
-
347 root_);
-
348 return result;
-
349 }
-
void traverse_postorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in post-order order.
Definition: binary_search_tree2.cpp:230
+
345 {
+ +
347 traverse_postorder([&](T node_value) { result.push_back(node_value); },
+
348 root_);
+
349 return result;
+
350 }
+
void traverse_postorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in post-order order.
Definition: binary_search_tree2.cpp:231
Here is the call graph for this function:
@@ -692,13 +692,13 @@ template<class T >

Get all values of the BST in pre-order order.

Returns
std::vector<T> List of values, sorted in pre-order order.
-
332 {
- -
334 traverse_preorder([&](T node_value) { result.push_back(node_value); },
-
335 root_);
-
336 return result;
-
337 }
-
void traverse_preorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in pre-order order.
Definition: binary_search_tree2.cpp:213
+
333 {
+ +
335 traverse_preorder([&](T node_value) { result.push_back(node_value); },
+
336 root_);
+
337 return result;
+
338 }
+
void traverse_preorder(std::function< void(T)> callback, std::unique_ptr< bst_node > &node)
Recursive function to traverse the tree in pre-order order.
Definition: binary_search_tree2.cpp:214
Here is the call graph for this function:
@@ -755,32 +755,32 @@ template<class T >
Returns
true If the insert operation was successful.
false Otherwise.
-
89 {
-
90 if (root_ == node && !root_) {
-
91 root_ = std::unique_ptr<bst_node>(new bst_node(new_value));
-
92 return true;
-
93 }
-
94
-
95 if (new_value < node->value) {
-
96 if (!node->left) {
-
97 node->left = std::unique_ptr<bst_node>(new bst_node(new_value));
-
98 return true;
-
99 } else {
-
100 return insert(node->left, new_value);
-
101 }
-
102 } else if (new_value > node->value) {
-
103 if (!node->right) {
-
104 node->right =
-
105 std::unique_ptr<bst_node>(new bst_node(new_value));
-
106 return true;
-
107 } else {
-
108 return insert(node->right, new_value);
-
109 }
-
110 } else {
-
111 return false;
-
112 }
-
113 }
-
bool insert(std::unique_ptr< bst_node > &node, T new_value)
Recursive function to insert a value into the BST.
Definition: binary_search_tree2.cpp:89
+
90 {
+
91 if (root_ == node && !root_) {
+
92 root_ = std::unique_ptr<bst_node>(new bst_node(new_value));
+
93 return true;
+
94 }
+
95
+
96 if (new_value < node->value) {
+
97 if (!node->left) {
+
98 node->left = std::unique_ptr<bst_node>(new bst_node(new_value));
+
99 return true;
+
100 } else {
+
101 return insert(node->left, new_value);
+
102 }
+
103 } else if (new_value > node->value) {
+
104 if (!node->right) {
+
105 node->right =
+
106 std::unique_ptr<bst_node>(new bst_node(new_value));
+
107 return true;
+
108 } else {
+
109 return insert(node->right, new_value);
+
110 }
+
111 } else {
+
112 return false;
+
113 }
+
114 }
+
bool insert(std::unique_ptr< bst_node > &node, T new_value)
Recursive function to insert a value into the BST.
Definition: binary_search_tree2.cpp:90
Here is the call graph for this function:
@@ -827,13 +827,13 @@ template<class T >
Returns
true If the insertion was successful.
false Otherwise.
-
258 {
-
259 bool result = insert(root_, new_value);
-
260 if (result) {
-
261 size_++;
-
262 }
-
263 return result;
-
264 }
+
259 {
+
260 bool result = insert(root_, new_value);
+
261 if (result) {
+
262 size_++;
+
263 }
+
264 return result;
+
265 }
Here is the call graph for this function:
@@ -897,49 +897,49 @@ template<class T >
Returns
true If the removal operation was successful.
false Otherwise.
-
125 {
-
126 if (!node) {
-
127 return false;
-
128 }
-
129
-
130 if (node->value == rm_value) {
-
131 if (node->left && node->right) {
-
132 T successor_node_value{};
-
133 find_max(node->left, successor_node_value);
-
134 remove(root_, root_, successor_node_value);
-
135 node->value = successor_node_value;
-
136 return true;
-
137 } else if (node->left || node->right) {
-
138 std::unique_ptr<bst_node>& non_null =
-
139 (node->left ? node->left : node->right);
-
140
-
141 if (node == root_) {
-
142 root_ = std::move(non_null);
-
143 } else if (rm_value < parent->value) {
-
144 parent->left = std::move(non_null);
-
145 } else {
-
146 parent->right = std::move(non_null);
-
147 }
-
148
-
149 return true;
-
150 } else {
-
151 if (node == root_) {
-
152 root_.reset(nullptr);
-
153 } else if (rm_value < parent->value) {
-
154 parent->left.reset(nullptr);
-
155 } else {
-
156 parent->right.reset(nullptr);
-
157 }
-
158
-
159 return true;
-
160 }
-
161 } else if (rm_value < node->value) {
-
162 return remove(node, node->left, rm_value);
-
163 } else {
-
164 return remove(node, node->right, rm_value);
-
165 }
-
166 }
-
bool remove(std::unique_ptr< bst_node > &parent, std::unique_ptr< bst_node > &node, T rm_value)
Recursive function to remove a value from the BST.
Definition: binary_search_tree2.cpp:124
+
126 {
+
127 if (!node) {
+
128 return false;
+
129 }
+
130
+
131 if (node->value == rm_value) {
+
132 if (node->left && node->right) {
+
133 T successor_node_value{};
+
134 find_max(node->left, successor_node_value);
+
135 remove(root_, root_, successor_node_value);
+
136 node->value = successor_node_value;
+
137 return true;
+
138 } else if (node->left || node->right) {
+
139 std::unique_ptr<bst_node>& non_null =
+
140 (node->left ? node->left : node->right);
+
141
+
142 if (node == root_) {
+
143 root_ = std::move(non_null);
+
144 } else if (rm_value < parent->value) {
+
145 parent->left = std::move(non_null);
+
146 } else {
+
147 parent->right = std::move(non_null);
+
148 }
+
149
+
150 return true;
+
151 } else {
+
152 if (node == root_) {
+
153 root_.reset(nullptr);
+
154 } else if (rm_value < parent->value) {
+
155 parent->left.reset(nullptr);
+
156 } else {
+
157 parent->right.reset(nullptr);
+
158 }
+
159
+
160 return true;
+
161 }
+
162 } else if (rm_value < node->value) {
+
163 return remove(node, node->left, rm_value);
+
164 } else {
+
165 return remove(node, node->right, rm_value);
+
166 }
+
167 }
+
bool remove(std::unique_ptr< bst_node > &parent, std::unique_ptr< bst_node > &node, T rm_value)
Recursive function to remove a value from the BST.
Definition: binary_search_tree2.cpp:125
T move(T... args)
Here is the call graph for this function:
@@ -986,13 +986,13 @@ template<class T >
Returns
true If the removal was successful.
false Otherwise.
-
273 {
-
274 bool result = remove(root_, root_, rm_value);
-
275 if (result) {
-
276 size_--;
-
277 }
-
278 return result;
-
279 }
+
274 {
+
275 bool result = remove(root_, root_, rm_value);
+
276 if (result) {
+
277 size_--;
+
278 }
+
279 return result;
+
280 }
Here is the call graph for this function:
@@ -1029,7 +1029,7 @@ template<class T >

Get the number of values in the BST.

Returns
std::size_t Number of values in the BST.
-
313{ return size_; }
+
314{ return size_; }
@@ -1077,15 +1077,15 @@ template<class T >
-
197 {
-
198 if (!node) {
-
199 return;
-
200 }
-
201
-
202 traverse_inorder(callback, node->left);
-
203 callback(node->value);
-
204 traverse_inorder(callback, node->right);
-
205 }
+
198 {
+
199 if (!node) {
+
200 return;
+
201 }
+
202
+
203 traverse_inorder(callback, node->left);
+
204 callback(node->value);
+
205 traverse_inorder(callback, node->right);
+
206 }
Here is the call graph for this function:
@@ -1139,15 +1139,15 @@ template<class T >
-
231 {
-
232 if (!node) {
-
233 return;
-
234 }
-
235
-
236 traverse_postorder(callback, node->left);
-
237 traverse_postorder(callback, node->right);
-
238 callback(node->value);
-
239 }
+
232 {
+
233 if (!node) {
+
234 return;
+
235 }
+
236
+
237 traverse_postorder(callback, node->left);
+
238 traverse_postorder(callback, node->right);
+
239 callback(node->value);
+
240 }
Here is the call graph for this function:
@@ -1201,15 +1201,15 @@ template<class T >
-
214 {
-
215 if (!node) {
-
216 return;
-
217 }
-
218
-
219 callback(node->value);
-
220 traverse_preorder(callback, node->left);
-
221 traverse_preorder(callback, node->right);
-
222 }
+
215 {
+
216 if (!node) {
+
217 return;
+
218 }
+
219
+
220 callback(node->value);
+
221 traverse_preorder(callback, node->left);
+
222 traverse_preorder(callback, node->right);
+
223 }
Here is the call graph for this function:
diff --git a/dd/db6/structbinary__search__tree_1_1bst__node.html b/dd/db6/structbinary__search__tree_1_1bst__node.html index 1dc2ad84c..478d12151 100644 --- a/dd/db6/structbinary__search__tree_1_1bst__node.html +++ b/dd/db6/structbinary__search__tree_1_1bst__node.html @@ -163,14 +163,14 @@ template<class T >
-
34 {
-
35 value = _value;
-
36 left = nullptr;
-
37 right = nullptr;
-
38 }
-
std::unique_ptr< bst_node > right
Definition: binary_search_tree2.cpp:27
-
T value
Definition: binary_search_tree2.cpp:25
-
std::unique_ptr< bst_node > left
Definition: binary_search_tree2.cpp:26
+
35 {
+
36 value = _value;
+
37 left = nullptr;
+
38 right = nullptr;
+
39 }
+
std::unique_ptr< bst_node > right
Definition: binary_search_tree2.cpp:28
+
T value
Definition: binary_search_tree2.cpp:26
+
std::unique_ptr< bst_node > left
Definition: binary_search_tree2.cpp:27
diff --git a/de/d33/binary__search__tree2_8cpp__incl.map b/de/d33/binary__search__tree2_8cpp__incl.map index a96795f59..9c513de2b 100644 --- a/de/d33/binary__search__tree2_8cpp__incl.map +++ b/de/d33/binary__search__tree2_8cpp__incl.map @@ -1,5 +1,5 @@ - + diff --git a/de/d33/binary__search__tree2_8cpp__incl.md5 b/de/d33/binary__search__tree2_8cpp__incl.md5 index 9eb0c254f..ee78584bf 100644 --- a/de/d33/binary__search__tree2_8cpp__incl.md5 +++ b/de/d33/binary__search__tree2_8cpp__incl.md5 @@ -1 +1 @@ -bb05f8f9ef281cfce7b458b281b3bb4d \ No newline at end of file +985cd26280c5c89c9ebea10263ce8b6e \ No newline at end of file diff --git a/de/d33/binary__search__tree2_8cpp__incl.svg b/de/d33/binary__search__tree2_8cpp__incl.svg index b8e5bd18f..35228e705 100644 --- a/de/d33/binary__search__tree2_8cpp__incl.svg +++ b/de/d33/binary__search__tree2_8cpp__incl.svg @@ -11,7 +11,7 @@ Node1 - + data_structures/binary _search_tree2.cpp diff --git a/df/d42/binary__search__tree2_8cpp.html b/df/d42/binary__search__tree2_8cpp.html index de6a2b462..4f9591320 100644 --- a/df/d42/binary__search__tree2_8cpp.html +++ b/df/d42/binary__search__tree2_8cpp.html @@ -104,7 +104,7 @@ $(document).ready(function(){initNavTree('df/d42/binary__search__tree2_8cpp.html
-

A generic binary search tree implementation. +

A generic binary search tree implementation. Here you can find more information about the algorithm: Scaler - Binary Search tree. More...

#include <cassert>
#include <functional>
@@ -157,7 +157,7 @@ Functions  

Detailed Description

-

A generic binary search tree implementation.

+

A generic binary search tree implementation. Here you can find more information about the algorithm: Scaler - Binary Search tree.

See also
binary_search_tree.cpp

Function Documentation

@@ -175,24 +175,24 @@ Functions
-
555 {
-
556 test_insert();
-
557 test_remove();
- - - - - - -
564}
-
static void test_get_elements_inorder()
Function for testing get_elements_inorder().
Definition: binary_search_tree2.cpp:497
-
static void test_contains()
Function for testing contains().
Definition: binary_search_tree2.cpp:428
-
static void test_insert()
Function for testing insert().
Definition: binary_search_tree2.cpp:357
-
static void test_get_elements_postorder()
Function for testing get_elements_postorder().
Definition: binary_search_tree2.cpp:539
-
static void test_find_max()
Function for testing find_max().
Definition: binary_search_tree2.cpp:474
-
static void test_get_elements_preorder()
Function for testing get_elements_preorder().
Definition: binary_search_tree2.cpp:518
-
static void test_remove()
Function for testing remove().
Definition: binary_search_tree2.cpp:391
-
static void test_find_min()
Function for testing find_min().
Definition: binary_search_tree2.cpp:451
+
556 {
+
557 test_insert();
+
558 test_remove();
+ + + + + + +
565}
+
static void test_get_elements_inorder()
Function for testing get_elements_inorder().
Definition: binary_search_tree2.cpp:498
+
static void test_contains()
Function for testing contains().
Definition: binary_search_tree2.cpp:429
+
static void test_insert()
Function for testing insert().
Definition: binary_search_tree2.cpp:358
+
static void test_get_elements_postorder()
Function for testing get_elements_postorder().
Definition: binary_search_tree2.cpp:540
+
static void test_find_max()
Function for testing find_max().
Definition: binary_search_tree2.cpp:475
+
static void test_get_elements_preorder()
Function for testing get_elements_preorder().
Definition: binary_search_tree2.cpp:519
+
static void test_remove()
Function for testing remove().
Definition: binary_search_tree2.cpp:392
+
static void test_find_min()
Function for testing find_min().
Definition: binary_search_tree2.cpp:452
@@ -221,27 +221,27 @@ Functions

Function for testing contains().

Returns
void
-
428 {
-
429 std::cout << "Testing BST contains...";
-
430
- -
432 tree.insert(5);
-
433 tree.insert(4);
-
434 tree.insert(3);
-
435 tree.insert(6);
-
436
-
437 assert(tree.contains(5));
-
438 assert(tree.contains(4));
-
439 assert(tree.contains(3));
-
440 assert(tree.contains(6));
-
441 assert(!tree.contains(999));
-
442
-
443 std::cout << "ok" << std::endl;
-
444}
+
429 {
+
430 std::cout << "Testing BST contains...";
+
431
+ +
433 tree.insert(5);
+
434 tree.insert(4);
+
435 tree.insert(3);
+
436 tree.insert(6);
+
437
+
438 assert(tree.contains(5));
+
439 assert(tree.contains(4));
+
440 assert(tree.contains(3));
+
441 assert(tree.contains(6));
+
442 assert(!tree.contains(999));
+
443
+
444 std::cout << "ok" << std::endl;
+
445}
-
The Binary Search Tree class.
Definition: binary_search_tree2.cpp:19
-
bool insert(std::unique_ptr< bst_node > &node, T new_value)
Recursive function to insert a value into the BST.
Definition: binary_search_tree2.cpp:89
-
bool contains(std::unique_ptr< bst_node > &node, T value)
Recursive function to check if a value is in the BST.
Definition: binary_search_tree2.cpp:176
+
The Binary Search Tree class.
Definition: binary_search_tree2.cpp:20
+
bool insert(std::unique_ptr< bst_node > &node, T new_value)
Recursive function to insert a value into the BST.
Definition: binary_search_tree2.cpp:90
+
bool contains(std::unique_ptr< bst_node > &node, T value)
Recursive function to check if a value is in the BST.
Definition: binary_search_tree2.cpp:177
T endl(T... args)
Here is the call graph for this function:
@@ -277,24 +277,24 @@ Here is the call graph for this function:

Function for testing find_max().

Returns
void
-
474 {
-
475 std::cout << "Testing BST find_max...";
-
476
-
477 int max = 0;
- -
479 assert(!tree.find_max(max));
-
480
-
481 tree.insert(5);
-
482 tree.insert(4);
-
483 tree.insert(3);
-
484 tree.insert(6);
-
485
-
486 assert(tree.find_max(max));
-
487 assert(max == 6);
-
488
-
489 std::cout << "ok" << std::endl;
-
490}
-
bool find_max(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the maximum value in the BST.
Definition: binary_search_tree2.cpp:52
+
475 {
+
476 std::cout << "Testing BST find_max...";
+
477
+
478 int max = 0;
+ +
480 assert(!tree.find_max(max));
+
481
+
482 tree.insert(5);
+
483 tree.insert(4);
+
484 tree.insert(3);
+
485 tree.insert(6);
+
486
+
487 assert(tree.find_max(max));
+
488 assert(max == 6);
+
489
+
490 std::cout << "ok" << std::endl;
+
491}
+
bool find_max(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the maximum value in the BST.
Definition: binary_search_tree2.cpp:53
T max(T... args)
Here is the call graph for this function:
@@ -330,24 +330,24 @@ Here is the call graph for this function:

Function for testing find_min().

Returns
void
-
451 {
-
452 std::cout << "Testing BST find_min...";
-
453
-
454 int min = 0;
- -
456 assert(!tree.find_min(min));
-
457
-
458 tree.insert(5);
-
459 tree.insert(4);
-
460 tree.insert(3);
-
461 tree.insert(6);
-
462
-
463 assert(tree.find_min(min));
-
464 assert(min == 3);
-
465
-
466 std::cout << "ok" << std::endl;
-
467}
-
bool find_min(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the minimum value in the BST.
Definition: binary_search_tree2.cpp:70
+
452 {
+
453 std::cout << "Testing BST find_min...";
+
454
+
455 int min = 0;
+ +
457 assert(!tree.find_min(min));
+
458
+
459 tree.insert(5);
+
460 tree.insert(4);
+
461 tree.insert(3);
+
462 tree.insert(6);
+
463
+
464 assert(tree.find_min(min));
+
465 assert(min == 3);
+
466
+
467 std::cout << "ok" << std::endl;
+
468}
+
bool find_min(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the minimum value in the BST.
Definition: binary_search_tree2.cpp:71
T min(T... args)
Here is the call graph for this function:
@@ -383,22 +383,22 @@ Here is the call graph for this function:

Function for testing get_elements_inorder().

Returns
void
-
497 {
-
498 std::cout << "Testing BST get_elements_inorder...";
-
499
- -
501 tree.insert(5);
-
502 tree.insert(4);
-
503 tree.insert(3);
-
504 tree.insert(6);
-
505
-
506 std::vector<int> expected = {3, 4, 5, 6};
- -
508 assert(actual == expected);
-
509
-
510 std::cout << "ok" << std::endl;
-
511}
-
std::vector< T > get_elements_inorder()
Get all values of the BST in in-order order.
Definition: binary_search_tree2.cpp:320
+
498 {
+
499 std::cout << "Testing BST get_elements_inorder...";
+
500
+ +
502 tree.insert(5);
+
503 tree.insert(4);
+
504 tree.insert(3);
+
505 tree.insert(6);
+
506
+
507 std::vector<int> expected = {3, 4, 5, 6};
+ +
509 assert(actual == expected);
+
510
+
511 std::cout << "ok" << std::endl;
+
512}
+
std::vector< T > get_elements_inorder()
Get all values of the BST in in-order order.
Definition: binary_search_tree2.cpp:321
Here is the call graph for this function:
@@ -434,22 +434,22 @@ Here is the call graph for this function:

Function for testing get_elements_postorder().

Returns
void
-
539 {
-
540 std::cout << "Testing BST get_elements_postorder...";
-
541
- -
543 tree.insert(5);
-
544 tree.insert(4);
-
545 tree.insert(3);
-
546 tree.insert(6);
-
547
-
548 std::vector<int> expected = {3, 4, 6, 5};
- -
550 assert(actual == expected);
-
551
-
552 std::cout << "ok" << std::endl;
-
553}
-
std::vector< T > get_elements_postorder()
Get all values of the BST in post-order order.
Definition: binary_search_tree2.cpp:344
+
540 {
+
541 std::cout << "Testing BST get_elements_postorder...";
+
542
+ +
544 tree.insert(5);
+
545 tree.insert(4);
+
546 tree.insert(3);
+
547 tree.insert(6);
+
548
+
549 std::vector<int> expected = {3, 4, 6, 5};
+ +
551 assert(actual == expected);
+
552
+
553 std::cout << "ok" << std::endl;
+
554}
+
std::vector< T > get_elements_postorder()
Get all values of the BST in post-order order.
Definition: binary_search_tree2.cpp:345
Here is the call graph for this function:
@@ -484,22 +484,22 @@ Here is the call graph for this function:

Function for testing get_elements_preorder().

Returns
void
-
518 {
-
519 std::cout << "Testing BST get_elements_preorder...";
-
520
- -
522 tree.insert(5);
-
523 tree.insert(4);
-
524 tree.insert(3);
-
525 tree.insert(6);
-
526
-
527 std::vector<int> expected = {5, 4, 3, 6};
- -
529 assert(actual == expected);
-
530
-
531 std::cout << "ok" << std::endl;
-
532}
-
std::vector< T > get_elements_preorder()
Get all values of the BST in pre-order order.
Definition: binary_search_tree2.cpp:332
+
519 {
+
520 std::cout << "Testing BST get_elements_preorder...";
+
521
+ +
523 tree.insert(5);
+
524 tree.insert(4);
+
525 tree.insert(3);
+
526 tree.insert(6);
+
527
+
528 std::vector<int> expected = {5, 4, 3, 6};
+ +
530 assert(actual == expected);
+
531
+
532 std::cout << "ok" << std::endl;
+
533}
+
std::vector< T > get_elements_preorder()
Get all values of the BST in pre-order order.
Definition: binary_search_tree2.cpp:333
Here is the call graph for this function:
@@ -534,35 +534,35 @@ Here is the call graph for this function:

Function for testing insert().

Returns
void
-
357 {
-
358 std::cout << "Testing BST insert...";
-
359
- -
361 bool res = tree.insert(5);
-
362 int min = -1, max = -1;
-
363 assert(res);
-
364 assert(tree.find_max(max));
-
365 assert(tree.find_min(min));
-
366 assert(max == 5);
-
367 assert(min == 5);
-
368 assert(tree.size() == 1);
-
369
-
370 tree.insert(4);
-
371 tree.insert(3);
-
372 tree.insert(6);
-
373 assert(tree.find_max(max));
-
374 assert(tree.find_min(min));
-
375 assert(max == 6);
-
376 assert(min == 3);
-
377 assert(tree.size() == 4);
-
378
-
379 bool fail_res = tree.insert(4);
-
380 assert(!fail_res);
-
381 assert(tree.size() == 4);
-
382
-
383 std::cout << "ok" << std::endl;
-
384}
-
std::size_t size()
Get the number of values in the BST.
Definition: binary_search_tree2.cpp:313
+
358 {
+
359 std::cout << "Testing BST insert...";
+
360
+ +
362 bool res = tree.insert(5);
+
363 int min = -1, max = -1;
+
364 assert(res);
+
365 assert(tree.find_max(max));
+
366 assert(tree.find_min(min));
+
367 assert(max == 5);
+
368 assert(min == 5);
+
369 assert(tree.size() == 1);
+
370
+
371 tree.insert(4);
+
372 tree.insert(3);
+
373 tree.insert(6);
+
374 assert(tree.find_max(max));
+
375 assert(tree.find_min(min));
+
376 assert(max == 6);
+
377 assert(min == 3);
+
378 assert(tree.size() == 4);
+
379
+
380 bool fail_res = tree.insert(4);
+
381 assert(!fail_res);
+
382 assert(tree.size() == 4);
+
383
+
384 std::cout << "ok" << std::endl;
+
385}
+
std::size_t size()
Get the number of values in the BST.
Definition: binary_search_tree2.cpp:314
Here is the call graph for this function:
@@ -597,38 +597,38 @@ Here is the call graph for this function:

Function for testing remove().

Returns
void
-
391 {
-
392 std::cout << "Testing BST remove...";
-
393
- -
395 tree.insert(5);
-
396 tree.insert(4);
-
397 tree.insert(3);
-
398 tree.insert(6);
-
399
-
400 bool res = tree.remove(5);
-
401 int min = -1, max = -1;
-
402 assert(res);
-
403 assert(tree.find_max(max));
-
404 assert(tree.find_min(min));
-
405 assert(max == 6);
-
406 assert(min == 3);
-
407 assert(tree.size() == 3);
-
408 assert(tree.contains(5) == false);
-
409
-
410 tree.remove(4);
-
411 tree.remove(3);
-
412 tree.remove(6);
-
413 assert(tree.size() == 0);
-
414 assert(tree.contains(6) == false);
-
415
-
416 bool fail_res = tree.remove(5);
-
417 assert(!fail_res);
-
418 assert(tree.size() == 0);
-
419
-
420 std::cout << "ok" << std::endl;
-
421}
-
bool remove(std::unique_ptr< bst_node > &parent, std::unique_ptr< bst_node > &node, T rm_value)
Recursive function to remove a value from the BST.
Definition: binary_search_tree2.cpp:124
+
392 {
+
393 std::cout << "Testing BST remove...";
+
394
+ +
396 tree.insert(5);
+
397 tree.insert(4);
+
398 tree.insert(3);
+
399 tree.insert(6);
+
400
+
401 bool res = tree.remove(5);
+
402 int min = -1, max = -1;
+
403 assert(res);
+
404 assert(tree.find_max(max));
+
405 assert(tree.find_min(min));
+
406 assert(max == 6);
+
407 assert(min == 3);
+
408 assert(tree.size() == 3);
+
409 assert(tree.contains(5) == false);
+
410
+
411 tree.remove(4);
+
412 tree.remove(3);
+
413 tree.remove(6);
+
414 assert(tree.size() == 0);
+
415 assert(tree.contains(6) == false);
+
416
+
417 bool fail_res = tree.remove(5);
+
418 assert(!fail_res);
+
419 assert(tree.size() == 0);
+
420
+
421 std::cout << "ok" << std::endl;
+
422}
+
bool remove(std::unique_ptr< bst_node > &parent, std::unique_ptr< bst_node > &node, T rm_value)
Recursive function to remove a value from the BST.
Definition: binary_search_tree2.cpp:125
Here is the call graph for this function:
diff --git a/dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html b/dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html index ba9f908f4..06e2d2f9e 100644 --- a/dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html +++ b/dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html @@ -115,7 +115,7 @@ Files  A simple tree implementation using structured nodes.
  file  binary_search_tree2.cpp - A generic binary search tree implementation.
+ A generic binary search tree implementation. Here you can find more information about the algorithm: Scaler - Binary Search tree.
  file  binaryheap.cpp  A C++ program to demonstrate common Binary Heap Operations.
diff --git a/files.html b/files.html index 6f5001cc7..7c3323e30 100644 --- a/files.html +++ b/files.html @@ -139,7 +139,7 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm  cll.h  avltree.cppA simple tree implementation using nodes  binary_search_tree.cppA simple tree implementation using structured nodes - binary_search_tree2.cppA generic binary search tree implementation + binary_search_tree2.cppA generic binary search tree implementation. Here you can find more information about the algorithm: Scaler - Binary Search tree  binaryheap.cppA C++ program to demonstrate common Binary Heap Operations  disjoint_set.cppDisjoint Sets Data Structure (Disjoint Sets)  dsu_path_compression.cppDSU (Disjoint sets)