Skip to content

Commit 4f4585d

Browse files
authored
docs: improve longest_palindromic_subsequence.cpp (TheAlgorithms#2467)
1 parent 4fc1471 commit 4f4585d

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

dynamic_programming/longest_palindromic_subsequence.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @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
55
*
66
* @details
77
* [Palindrome](https://en.wikipedia.org/wiki/Palindrome) string sequence of
@@ -18,8 +18,15 @@
1818
#include <vector> /// for std::vector
1919

2020
/**
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
2227
* subsequence of a string
28+
* @param a string whose longest palindromic subsequence is to be found
29+
* @returns longest palindromic subsequence of the string
2330
*/
2431
std::string lps(const std::string& a) {
2532
const auto b = std::string(a.rbegin(), a.rend());
@@ -70,17 +77,22 @@ std::string lps(const std::string& a) {
7077

7178
return ans;
7279
}
80+
} // namespace dynamic_programming
7381

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("") == "");
8091
}
8192

8293
/**
83-
* Main Function
94+
* @brief Main Function
95+
* @returns 0 on exit
8496
*/
8597
int main() {
8698
test(); // execute the tests

0 commit comments

Comments
 (0)