From 709e37973a8e66e6550fe85b910ec24c6f6213ca Mon Sep 17 00:00:00 2001 From: David Leal Date: Mon, 12 Jun 2023 05:53:58 +0000 Subject: [PATCH] chore: fix minor doc. issues and indentation --- dynamic_programming/lcs.c | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/dynamic_programming/lcs.c b/dynamic_programming/lcs.c index 516fa48f..bf360b73 100644 --- a/dynamic_programming/lcs.c +++ b/dynamic_programming/lcs.c @@ -1,12 +1,15 @@ /** * @file - * @brief [Longest Common Subsequence](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) algorithm + * @brief [Longest Common + * Subsequence](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) + * algorithm * @details * From Wikipedia: The longest common subsequence (LCS) problem is the problem - * of finding the longest subsequence common to all sequences in a set of sequences - * (often just two sequences). + * of finding the longest subsequence common to all sequences in a set of + * sequences (often just two sequences). * @author [Kurtz](https://github.com/itskurtz) */ + #include /* for io operations */ #include /* for memory management & exit */ #include /* for string manipulation & ooperations */ @@ -15,13 +18,13 @@ enum {LEFT, UP, DIAG}; /** - * @breif Computes LCS between s1 and s2 using a dynamic-programming approach - * @param1 s1 first null-terminated string - * @param2 s2 second null-terminated string - * @param3 l1 length of s1 - * @param4 l2 length of s2 - * @param5 L matrix of size l1 x l2 - * @param6 B matrix of size l1 x l2 + * @brief Computes LCS between s1 and s2 using a dynamic-programming approach + * @param s1 first null-terminated string + * @param s2 second null-terminated string + * @param l1 length of s1 + * @param l2 length of s2 + * @param L matrix of size l1 x l2 + * @param B matrix of size l1 x l2 * @returns void */ void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B) { @@ -50,12 +53,12 @@ void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B) { } /** - * @breif Builds the LCS according to B using a traceback approach - * @param1 s1 first null-terminated string - * @param2 l1 length of s1 - * @param3 l2 length of s2 - * @param4 L matrix of size l1 x l2 - * @param5 B matrix of size l1 x l2 + * @brief Builds the LCS according to B using a traceback approach + * @param s1 first null-terminated string + * @param l1 length of s1 + * @param l2 length of s2 + * @param L matrix of size l1 x l2 + * @param B matrix of size l1 x l2 * @returns lcs longest common subsequence */ char *lcsbuild(const char *s1, int l1, int l2, int **L, int **B) { @@ -78,15 +81,18 @@ char *lcsbuild(const char *s1, int l1, int l2, int **L, int **B) { i = i - 1; j = j - 1; } - else if (B[i][j] == LEFT) { + else if (B[i][j] == LEFT) + { j = j - 1; } - else { + else + { i = i - 1; } } return lcs; } + /** * @brief Self-test implementations * @returns void @@ -136,8 +142,9 @@ static void test() { printf("LCS len:%3d\n", L[l1][l2]); printf("LCS: %s\n", lcs); - free(lcs); - for (j = 0; j <= l1; j++) { + free(lcs); + for (j = 0; j <= l1; j++) + { free(L[j]), free(B[j]); } free(L);