Skip to content

Commit bec324e

Browse files
committed
update comments
1 parent 38ac0e7 commit bec324e

File tree

75 files changed

+913
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+913
-606
lines changed

cpp-algorithm/src/array/advancing_through.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
namespace AdvancingThrough
77
{
8-
/// @brief Advance through the array to the last index.
9-
/// @param max_advance_steps maximum number of steps that can be taken from each index
10-
/// @return either reach the end or not
8+
/**
9+
* \brief Advance through the array to the last index.
10+
* \param max_advance_steps maximum number of steps that can be taken from each index
11+
* \return either reach the end or not
12+
*/
1113
auto CanReachEnd(const std::vector<int>& max_advance_steps) -> bool;
1214
}
1315

cpp-algorithm/src/array/delete_element.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55

66
namespace DeleteElement
77
{
8-
/// @brief Delete duplicate elements in the array.
9-
/// @param numbers input array
10-
/// @return result array
8+
/**
9+
* \brief Delete duplicate elements in the array.
10+
* \param numbers input array
11+
* \return result array
12+
*/
1113
auto DeleteDuplicates(std::vector<int>& numbers) -> std::vector<int>;
1214

13-
/// @brief Delete duplicate elements in the array.
14-
/// @param numbers input array
15-
/// @return result array
15+
/**
16+
* \brief Delete duplicate elements in the array.
17+
* \param numbers input array
18+
* \return result array
19+
*/
1620
auto DeleteDuplicateElements(std::vector<int>& numbers) -> std::vector<int>;
1721

18-
/// @brief Delete specific elements in the array.
19-
/// @param numbers input array
20-
/// @param element specific element
21-
/// @return result array
22+
/**
23+
* \brief Delete specific elements in the array.
24+
* \param numbers input array
25+
* \param element specific element
26+
* \return result array
27+
*/
2228
auto DeleteSpecificElements(std::vector<int>& numbers, int element) -> std::vector<int>;
2329
}
2430

cpp-algorithm/src/array/dutch_national_flag.h

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,38 @@
55

66
namespace DutchFlag
77
{
8-
/// @brief Color enum
8+
/**
9+
* \brief Color enum
10+
*/
911
enum Color
1012
{
1113
Red,
1214
White,
1315
Blue
1416
};
1517

16-
/// @brief Dutch national flag problem.
17-
/// @param pivot_index pivot index
18-
/// @param arr input array
19-
/// @return result array
18+
/**
19+
* \brief Dutch national flag problem.
20+
* \param pivot_index pivot index
21+
* \param arr input array
22+
* \return result array
23+
*/
2024
auto DutchFlagPartition1(int pivot_index, std::vector<Color>& arr) -> std::vector<Color>;
2125

22-
/// @brief Dutch national flag problem.
23-
/// @param pivot_index pivot index
24-
/// @param arr input array
25-
/// @return result array
26+
/**
27+
* \brief Dutch national flag problem.
28+
* \param pivot_index pivot index
29+
* \param arr input array
30+
* \return result array
31+
*/
2632
auto DutchFlagPartition2(int pivot_index, std::vector<Color>& arr) -> std::vector<Color>;
2733

28-
/// @brief Dutch national flag problem.
29-
/// @param pivot_index pivot index
30-
/// @param arr input array
31-
/// @return result array
34+
/**
35+
* \brief Dutch national flag problem.
36+
* \param pivot_index pivot index
37+
* \param arr input array
38+
* \return result array
39+
*/
3240
auto DutchFlagPartition3(int pivot_index, std::vector<Color>& arr) -> std::vector<Color>;
3341
}
3442

cpp-algorithm/src/array/enumerate_prime_number.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
namespace EnumeratePrime
77
{
8-
/// @brief Enumerate prime numbers in the range.
9-
/// @param n upper bound
10-
/// @return prime numbers
8+
/**
9+
* brief Enumerate prime numbers in the range.
10+
* param n upper bound
11+
* return prime numbers
12+
*/
1113
auto GeneratePrimes(int n) -> std::vector<int>;
1214
}
1315

cpp-algorithm/src/array/order_element.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55

66
namespace OrderElement
77
{
8-
/// @brief Order even and odd numbers in the array.
9-
/// @param arr numbers
8+
/**
9+
* \brief Order even and odd numbers in the array.
10+
* \param arr numbers
11+
*/
1012
void EvenOdd(std::vector<int>& arr);
1113

12-
/// @brief Rearrange arrays to have a specific order.
13-
/// A[0] <= A[1] >= A[2] <= A[3] >= A[4] <= A[5] >= ...
14-
/// @param numbers input array
15-
/// @return ordered array
14+
/**
15+
* \brief Rearrange arrays to have a specific order.
16+
* A[0] <= A[1] >= A[2] <= A[3] >= A[4] <= A[5] >= ...
17+
* \param numbers input array
18+
* \return ordered array
19+
*/
1620
auto Rearrange(std::vector<int>& numbers) -> std::vector<int>;
1721
}
1822

cpp-algorithm/src/array/random_data_sampling.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@
55

66
namespace RandomDataSampling
77
{
8-
/// @brief Randomly select k elements from the array.
9-
/// @param k sample size
10-
/// @param arr input array
11-
/// @return result array
8+
/**
9+
* \brief Randomly select k elements from the array.
10+
* \param k sample size
11+
* \param arr input array
12+
* \return result array
13+
*/
1214
auto OfflineRandomSampling(int k, std::vector<int>& arr) -> std::vector<int>;
1315

14-
// TODO: OnlineRandomSampling
15-
/// @brief Randomly select k elements from the array.
16-
/// @param begin begin iterator
17-
/// @param end end iterator
18-
/// @param k sample size
19-
/// @return result array
16+
// TODO: Implement OnlineRandomSampling
17+
/**
18+
* \brief Randomly select k elements from the array.
19+
* \param begin begin iterator
20+
* \param end end iterator
21+
* \param k sample size
22+
* \return result array
23+
*/
2024
auto OnlineRandomSampling(const std::vector<int>::const_iterator& begin,
2125
const std::vector<int>::const_iterator& end, int k) -> std::vector<int>;
2226

23-
/// @brief Compute permutation of the array generated by random sampling.
24-
/// @param n sample size
25-
/// @return result array
27+
/**
28+
* \brief Compute permutation of the array generated by random sampling.
29+
* \param n sample size
30+
* \return result array
31+
*/
2632
auto ComputeRandomPermutation(int n) -> std::vector<int>;
2733
}
2834

cpp-algorithm/src/array/replace_element.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,33 @@
66

77
namespace ReplaceElement
88
{
9-
/// @brief Replace element and remove element in the array. Keep the array size.
10-
/// @param arr input array
11-
/// @param replace_str replace string
12-
/// @param remove_str remove string
13-
/// @return result array
9+
/**
10+
* \brief Replace element and remove element in the array. Keep the array size.
11+
* \param arr input array
12+
* \param replace_str replace string
13+
* \param remove_str remove string
14+
* \return result array
15+
*/
1416
auto ReplaceAndRemoveString1(std::vector<std::string>& arr, const std::string& replace_str,
1517
const std::string& remove_str) -> std::vector<std::string>;
1618

17-
/// @brief Replace element and remove element in the array.
18-
/// Use some STL algorithms.
19-
/// @param arr input array
20-
/// @param replace_str replace string
21-
/// @param remove_str remove string
22-
/// @return result array
19+
/**
20+
* \brief Replace element and remove element in the array.
21+
* Use some STL algorithms.
22+
* \param arr input array
23+
* \param replace_str replace string
24+
* \param remove_str remove string
25+
* \return result array
26+
*/
2327
auto ReplaceAndRemoveString2(std::vector<std::string>& arr, const std::string& replace_str,
2428
const std::string& remove_str) -> std::vector<std::string>;
2529

26-
/// @brief Telex encoding for punctuation marks.
27-
/// Replace '.' with 'DOT', ',' with 'COMMA', '?' with 'QUESTION_MARK', '!' with 'EXCLAMATION_MARK'.
28-
/// @param arr input array (possibly contains punctuation marks)
29-
/// @return result array
30+
/**
31+
* \brief Telex encoding for punctuation marks.
32+
* Replace '.' with 'DOT', ',' with 'COMMA', '?' with 'QUESTION_MARK', '!' with 'EXCLAMATION_MARK'.
33+
* \param arr input array (possibly contains punctuation marks)
34+
* \return result array
35+
*/
3036
auto TelexEncoding(std::vector<std::string>& arr) -> std::vector<std::string>;
3137
}
3238

cpp-algorithm/src/dynamic_programming/longest_common_subsequence.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@
77

88
namespace CommonSubsequence
99
{
10-
/// @brief Compute the length of an LCS of two sequences
11-
/// @param seq1 string sequence 1
12-
/// @param seq2 string sequence 2
13-
/// @return length and direction matrices
10+
/**
11+
* \brief Compute the length of an LCS of two sequences
12+
* \param seq1 string sequence 1
13+
* \param seq2 string sequence 2
14+
* \return length and direction matrices
15+
*/
1416
auto LongestCommonSubsequenceLength(const std::string& seq1, const std::string& seq2)
1517
-> std::tuple<gsl_matrix_int*, gsl_matrix_char*>;
1618

17-
/// @brief Constructing an LCS from the length matrix
18-
/// @param seq1 string sequence 1
19-
/// @param direction_matrix direction matrix
20-
/// @param length1 length of the string sequence 1
21-
/// @param length2 length of the string sequence 2
22-
/// @param result LCS string
19+
/**
20+
* \brief Constructing an LCS from the length matrix
21+
* \param seq1 string sequence 1
22+
* \param direction_matrix direction matrix
23+
* \param length1 length of the string sequence 1
24+
* \param length2 length of the string sequence 2
25+
* \param result LCS string
26+
*/
2327
void LongestCommonSubsequence(const std::string& seq1, const gsl_matrix_char* direction_matrix, int length1,
2428
int length2, std::string& result);
2529

26-
/// @brief Print table of LCS lengths
27-
/// @param seq1 string sequence 1
28-
/// @param seq2 string sequence 2
29-
/// @param direction_matrix direction matrix
30+
/**
31+
* \brief Print table of LCS lengths
32+
* \param seq1 string sequence 1
33+
* \param seq2 string sequence 2
34+
* \param direction_matrix direction matrix
35+
*/
3036
void PrintOptimalMatrix(const std::string& seq1, const std::string& seq2, const gsl_matrix_char* direction_matrix);
3137
}
3238

cpp-algorithm/src/dynamic_programming/rod_cutting.h

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@
66

77
namespace RodCutting
88
{
9-
/// @brief Rod cutting algorithm to call recursively.
10-
/// @param price prices for rod length
11-
/// @param length length of a rod
12-
/// @return the maximum revenue
9+
/**
10+
* \brief Rod cutting algorithm to call recursively.
11+
* \param price prices for rod length
12+
* \param length length of a rod
13+
* \return the maximum revenue
14+
*/
1315
auto CutRod(const std::map<int, int>& price, int length) -> int;
1416

15-
/// @brief Rod cutting algorithm with memoization that use top-down approach.
16-
/// @param price prices for rod length
17-
/// @param length length of a rod
18-
/// @return the maximum revenue
17+
/**
18+
* \brief Rod cutting algorithm with memoization that use top-down approach.
19+
* \param price prices for rod length
20+
* \param length length of a rod
21+
* \return the maximum revenue
22+
*/
1923
auto MemoizedCutRod(const std::map<int, int>& price, int length) -> int;
2024

21-
/// @brief Sub procedure for rod cutting algorithm with memoization.
22-
/// This use auxiliary array for memoization.
23-
/// @param price prices for rod length
24-
/// @param length length of a rod
25-
/// @param memo memoized results
26-
/// @return the maximum revenue
25+
/**
26+
* \brief Sub procedure for rod cutting algorithm with memoization.
27+
* This use auxiliary array for memoization.
28+
* \param price prices for rod length
29+
* \param length length of a rod
30+
* \param memo memoized results
31+
* \return the maximum revenue
32+
*/
2733
auto MemoizedCutRodAux(const std::map<int, int>& price, int length, std::vector<int>& memo) -> int;
2834

29-
/// @brief Rod cutting algorithm that use bottom-up approach.
30-
/// @param price prices for rod length
31-
/// @param length length of a rod
32-
/// @return the maximum revenue
35+
/**
36+
* \brief Rod cutting algorithm that use bottom-up approach.
37+
* \param price prices for rod length
38+
* \param length length of a rod
39+
* \return the maximum revenue
40+
*/
3341
auto BottomUpCutRod(const std::map<int, int>& price, int length) -> int;
3442

35-
/// @brief Rod cutting algorithm that computes the maximum revenue and the optimal size of the first piece for given
36-
/// rod length.
37-
/// @param price prices for rod length
38-
/// @param length length of a rod
39-
/// @return the maximum revenue and the optimal size of the first piece
43+
/**
44+
* \brief Rod cutting algorithm that computes the maximum revenue and the optimal size of the first piece for given
45+
* rod length.
46+
* \param price prices for rod length
47+
* \param length length of a rod
48+
* \return the maximum revenue and the optimal size of the first piece
49+
*/
4050
auto ExtendedBottomUpCutRod(const std::map<int, int>& price, int length) -> std::tuple<int, int>;
4151
}
4252

cpp-algorithm/src/graph/bellman_ford.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ namespace BellmanFord
2626
void AddVertex(Vertex& v);
2727
void AddEdge(Vertex& u, Vertex& v, int weight);
2828

29-
/// @brief Bellman-Ford algorithm. Find the shortest path from a source vertex to all other vertices.
30-
/// @details A single source shortest path algorithm that can handle negative edge weights.
31-
/// It finds the shortest path from a source vertex to all other vertices in a weighted graph.
32-
/// @param source source vertex
29+
/**
30+
* \brief Bellman-Ford algorithm. Find the shortest path from a source vertex to all other vertices.
31+
* \details A single source shortest path algorithm that can handle negative edge weights.
32+
* It finds the shortest path from a source vertex to all other vertices in a weighted graph.
33+
* \param source source vertex
34+
*/
3335
void BellmanFordAlgorithm(Vertex& source);
3436

3537
std::vector<Vertex*> vertices;

cpp-algorithm/src/graph/breadth_first_search.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ namespace Bfs
3030
class Graph
3131
{
3232
public:
33-
/// @brief Breadth first search algorithm.
34-
/// @details A search algorithm that traverses a graph layer by layer.
35-
/// @param start starting vertex
36-
/// @param goal goal vertex
37-
/// @return goal vertex
33+
/**
34+
* \brief Breadth first search algorithm.
35+
* \details A search algorithm that traverses a graph layer by layer.
36+
* \param start starting vertex
37+
* \param goal goal vertex
38+
* \return goal vertex
39+
*/
3840
static auto BreadthFirstSearch(Vertex& start, const Vertex& goal) -> Vertex*;
3941

4042
void AddVertex(Vertex& v);

0 commit comments

Comments
 (0)