1. Engineering
  2. Computer Science
  3. c longest common subsequence ive got it to work with...

Question: c longest common subsequence ive got it to work with...

Question details

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.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution