Skip to content

Commit 3e7c9f4

Browse files
committed
correct documentation and tests
1 parent 0c9a836 commit 3e7c9f4

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

data_structures/avltree.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* \file
3-
* \brief An implementation of AVL tree.
2+
* @file
3+
* @brief An implementation of AVL tree.
44
*/
55
#include <algorithm> /// for std::max
66
#include <cassert> /// for assert
@@ -10,14 +10,30 @@
1010
#include <sstream> /// for std::ostringstream
1111
#include <vector> /// for std::vector
1212

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+
*/
1319
class AVLTree {
1420
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+
*/
1526
struct Node {
1627
int data;
1728
int height;
1829
std::unique_ptr<Node> left;
1930
std::unique_ptr<Node> right;
2031

32+
/**
33+
* @brief Constructor for Node, used to simplify node and
34+
* smart pointer construction.
35+
* @param val the value of the node
36+
*/
2137
Node(int val) : data(val), height(1), left(nullptr), right(nullptr) {}
2238
};
2339

@@ -216,7 +232,7 @@ class AVLTree {
216232
/**
217233
* @brief Function for testing insert().
218234
*
219-
* @returns `void`
235+
* @returns void
220236
*/
221237
static void test_insert() {
222238
std::cout << "Testing AVL insert...";
@@ -257,7 +273,7 @@ static void test_insert() {
257273
/**
258274
* @brief Function for testing deleteNode().
259275
*
260-
* @returns `void`
276+
* @returns void
261277
*/
262278
static void test_deleteNode() {
263279
std::cout << "Testing AVL deleteNode...";
@@ -310,7 +326,7 @@ static void test_deleteNode() {
310326
/**
311327
* @brief Function for testing levelOrder().
312328
*
313-
* @returns `void`
329+
* @returns void
314330
*/
315331
static void test_levelOrder() {
316332
std::cout << "Testing AVL levelOrder...";
@@ -336,7 +352,7 @@ static void test_levelOrder() {
336352
/**
337353
* @brief Function for testing tree balancing.
338354
*
339-
* @returns `void`
355+
* @returns void
340356
*/
341357
static void test_balancing() {
342358
std::cout << "Testing AVL balancing...";
@@ -376,7 +392,7 @@ static void test_balancing() {
376392
/**
377393
* @brief Function for testing edge cases.
378394
*
379-
* @returns `void`
395+
* @returns void
380396
*/
381397
static void test_edge_cases() {
382398
std::cout << "Testing AVL edge cases...";
@@ -411,16 +427,25 @@ static void test_edge_cases() {
411427
}
412428

413429
/**
414-
* @brief Main function for running tests.
430+
* @brief Function for running tests.
415431
*
416-
* @returns 0 on exit
432+
* @returns void
417433
*/
418-
int main() {
434+
void tests() {
419435
test_insert();
420436
test_deleteNode();
421437
test_levelOrder();
422438
test_balancing();
423439
test_edge_cases();
424440
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();
425450
return 0;
426-
}
451+
}

0 commit comments

Comments
 (0)