Anonymous user
Longest common subsequence: Difference between revisions
→{{header|C}}
(Added JavaScript) |
|||
Line 173:
#define MAX(A,B) (((A)>(B))? (A) : (B))
char * lcs(const char *a,const char * b) {
int lena = strlen(a)+1;
int lenb = strlen(b)+1;
Line 181:
int i,j;
const char *x, *y;
int *la = (int *)calloc(lena*lenb, sizeof( int));
int **lengths = (int **)malloc( lena*sizeof( int*));
Line 199:
result = bufr+bufrlen;
*--result = '\0';
i = lena-1; j = lenb-1;
while ( (i>0) && (j>0) ) {
Line 214:
}</lang>
Testing
<lang c>int main(
{
printf("%s\n", lcs("thisisatest", "testing123testing")); // tsitest
|