Question: C++ Longest Common Subsequence: I've got it to work with 2 char arrays, and trying to implement the same algorithm with 3 char arrays but
C++ Longest Common Subsequence:
I've got it to work with 2 char arrays, and trying to implement the same algorithm with 3 char arrays but won't work.
int LCS3(char *chararray1, char *chararray2, char *chararray3, int a=0, int b=0, int c=0) { if (chararray1[a] == '\0' || chararray2[b] == '\0' || chararray3[c] == '\0') { return 0; } else if (chararray1[a] == chararray2[b] && chararray1[a] == chararray3[c]){ return 1 + LCS3(chararray1, chararray2, chararray3, a + 1, b + 1, c + 1); } else { return max(LCS3(chararray1, chararray2, chararray3, a + 1, b, c), LCS3(chararray1, chararray2, chararray3, a, b + 1, c), LCS3(chararray1, chararray2, chararray3, a, b, c + 1)); } }
Is there a way to fix this or is there another way to go around it. Any help will be appriacted.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
