mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
docs: improve longest_palindromic_subsequence.cpp
(#2467)
This commit is contained in:
parent
4fc14710b6
commit
4f4585d4c1
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief Program to find the Longest Palindormic
|
* @brief Program to find the [Longest Palindormic
|
||||||
* Subsequence of a string
|
* Subsequence](https://www.geeksforgeeks.org/longest-palindromic-subsequence-dp-12/) of a string
|
||||||
*
|
*
|
||||||
* @details
|
* @details
|
||||||
* [Palindrome](https://en.wikipedia.org/wiki/Palindrome) string sequence of
|
* [Palindrome](https://en.wikipedia.org/wiki/Palindrome) string sequence of
|
||||||
@ -18,8 +18,15 @@
|
|||||||
#include <vector> /// for std::vector
|
#include <vector> /// for std::vector
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that returns the longest palindromic
|
* @namespace
|
||||||
|
* @brief Dynamic Programming algorithms
|
||||||
|
*/
|
||||||
|
namespace dynamic_programming {
|
||||||
|
/**
|
||||||
|
* @brief Function that returns the longest palindromic
|
||||||
* subsequence of a string
|
* subsequence of a string
|
||||||
|
* @param a string whose longest palindromic subsequence is to be found
|
||||||
|
* @returns longest palindromic subsequence of the string
|
||||||
*/
|
*/
|
||||||
std::string lps(const std::string& a) {
|
std::string lps(const std::string& a) {
|
||||||
const auto b = std::string(a.rbegin(), a.rend());
|
const auto b = std::string(a.rbegin(), a.rend());
|
||||||
@ -70,17 +77,22 @@ std::string lps(const std::string& a) {
|
|||||||
|
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
} // namespace dynamic_programming
|
||||||
|
|
||||||
/** Test function */
|
/**
|
||||||
void test() {
|
* @brief Self-test implementations
|
||||||
assert(lps("radar") == "radar");
|
* @returns void
|
||||||
assert(lps("abbcbaa") == "abcba");
|
*/
|
||||||
assert(lps("bbbab") == "bbbb");
|
static void test() {
|
||||||
assert(lps("") == "");
|
assert(dynamic_programming::lps("radar") == "radar");
|
||||||
|
assert(dynamic_programming::lps("abbcbaa") == "abcba");
|
||||||
|
assert(dynamic_programming::lps("bbbab") == "bbbb");
|
||||||
|
assert(dynamic_programming::lps("") == "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Function
|
* @brief Main Function
|
||||||
|
* @returns 0 on exit
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
test(); // execute the tests
|
test(); // execute the tests
|
||||||
|
Loading…
Reference in New Issue
Block a user