|
1 | 1 | /**
|
2 | 2 | * @file
|
3 |
| - * @brief Program to find the Longest Palindormic |
4 |
| - * Subsequence of a string |
| 3 | + * @brief Program to find the [Longest Palindormic |
| 4 | + * Subsequence](https://www.geeksforgeeks.org/longest-palindromic-subsequence-dp-12/) of a string |
5 | 5 | *
|
6 | 6 | * @details
|
7 | 7 | * [Palindrome](https://en.wikipedia.org/wiki/Palindrome) string sequence of
|
|
18 | 18 | #include <vector> /// for std::vector
|
19 | 19 |
|
20 | 20 | /**
|
21 |
| - * Function that returns the longest palindromic |
| 21 | + * @namespace |
| 22 | + * @brief Dynamic Programming algorithms |
| 23 | + */ |
| 24 | +namespace dynamic_programming { |
| 25 | +/** |
| 26 | + * @brief Function that returns the longest palindromic |
22 | 27 | * subsequence of a string
|
| 28 | + * @param a string whose longest palindromic subsequence is to be found |
| 29 | + * @returns longest palindromic subsequence of the string |
23 | 30 | */
|
24 | 31 | std::string lps(const std::string& a) {
|
25 | 32 | const auto b = std::string(a.rbegin(), a.rend());
|
@@ -70,17 +77,22 @@ std::string lps(const std::string& a) {
|
70 | 77 |
|
71 | 78 | return ans;
|
72 | 79 | }
|
| 80 | +} // namespace dynamic_programming |
73 | 81 |
|
74 |
| -/** Test function */ |
75 |
| -void test() { |
76 |
| - assert(lps("radar") == "radar"); |
77 |
| - assert(lps("abbcbaa") == "abcba"); |
78 |
| - assert(lps("bbbab") == "bbbb"); |
79 |
| - assert(lps("") == ""); |
| 82 | +/** |
| 83 | + * @brief Self-test implementations |
| 84 | + * @returns void |
| 85 | + */ |
| 86 | +static void test() { |
| 87 | + assert(dynamic_programming::lps("radar") == "radar"); |
| 88 | + assert(dynamic_programming::lps("abbcbaa") == "abcba"); |
| 89 | + assert(dynamic_programming::lps("bbbab") == "bbbb"); |
| 90 | + assert(dynamic_programming::lps("") == ""); |
80 | 91 | }
|
81 | 92 |
|
82 | 93 | /**
|
83 |
| - * Main Function |
| 94 | + * @brief Main Function |
| 95 | + * @returns 0 on exit |
84 | 96 | */
|
85 | 97 | int main() {
|
86 | 98 | test(); // execute the tests
|
|
0 commit comments