1
1
/* *
2
- * \ file
3
- * \ brief An implementation of AVL tree.
2
+ * @ file
3
+ * @ brief An implementation of AVL tree.
4
4
*/
5
5
#include < algorithm> // / for std::max
6
6
#include < cassert> // / for assert
10
10
#include < sstream> // / for std::ostringstream
11
11
#include < vector> // / for std::vector
12
12
13
+ /* *
14
+ * @brief Class for AVL tree.
15
+ * @details AVL tree is a self-balancing binary search tree where the difference
16
+ * between heights of left and right subtrees cannot be more than one for all
17
+ * nodes.
18
+ */
13
19
class AVLTree {
14
20
public:
21
+ /* *
22
+ * @brief Node structure for AVL tree
23
+ * @details Contains the data, height of the node and pointers to left and
24
+ * right child nodes.
25
+ */
15
26
struct Node {
16
27
int data;
17
28
int height;
18
29
std::unique_ptr<Node> left;
19
30
std::unique_ptr<Node> right;
20
31
32
+ /* *
33
+ * @brief Constructor for Node, used to simplify node and
34
+ * smart pointer construction.
35
+ * @param val the value of the node
36
+ */
21
37
Node (int val) : data(val), height(1 ), left(nullptr ), right(nullptr ) {}
22
38
};
23
39
@@ -216,7 +232,7 @@ class AVLTree {
216
232
/* *
217
233
* @brief Function for testing insert().
218
234
*
219
- * @returns ` void`
235
+ * @returns void
220
236
*/
221
237
static void test_insert () {
222
238
std::cout << " Testing AVL insert..." ;
@@ -257,7 +273,7 @@ static void test_insert() {
257
273
/* *
258
274
* @brief Function for testing deleteNode().
259
275
*
260
- * @returns ` void`
276
+ * @returns void
261
277
*/
262
278
static void test_deleteNode () {
263
279
std::cout << " Testing AVL deleteNode..." ;
@@ -310,7 +326,7 @@ static void test_deleteNode() {
310
326
/* *
311
327
* @brief Function for testing levelOrder().
312
328
*
313
- * @returns ` void`
329
+ * @returns void
314
330
*/
315
331
static void test_levelOrder () {
316
332
std::cout << " Testing AVL levelOrder..." ;
@@ -336,7 +352,7 @@ static void test_levelOrder() {
336
352
/* *
337
353
* @brief Function for testing tree balancing.
338
354
*
339
- * @returns ` void`
355
+ * @returns void
340
356
*/
341
357
static void test_balancing () {
342
358
std::cout << " Testing AVL balancing..." ;
@@ -376,7 +392,7 @@ static void test_balancing() {
376
392
/* *
377
393
* @brief Function for testing edge cases.
378
394
*
379
- * @returns ` void`
395
+ * @returns void
380
396
*/
381
397
static void test_edge_cases () {
382
398
std::cout << " Testing AVL edge cases..." ;
@@ -411,16 +427,25 @@ static void test_edge_cases() {
411
427
}
412
428
413
429
/* *
414
- * @brief Main function for running tests.
430
+ * @brief Function for running tests.
415
431
*
416
- * @returns 0 on exit
432
+ * @returns void
417
433
*/
418
- int main () {
434
+ void tests () {
419
435
test_insert ();
420
436
test_deleteNode ();
421
437
test_levelOrder ();
422
438
test_balancing ();
423
439
test_edge_cases ();
424
440
std::cout << " All tests passed!" << std::endl;
441
+ }
442
+
443
+ /* *
444
+ * @brief Main function for running tests.
445
+ *
446
+ * @returns 0 on exit
447
+ */
448
+ int main () {
449
+ tests ();
425
450
return 0 ;
426
- }
451
+ }
0 commit comments