char * suff[100];
int pstrcmp(const void p, const void *q)
{
return strcmp((char**)p,*(char**)q);
}
int comlen_suff(char * p, char * q)
{
int len = 0;
while(*p && *q && *p++ == *q++)
{
++len;
if(*p == '#' || *q == '#')
{
return len;
}
}
return 0;
}
void LCS_suffix(char * X, int xlen, char * Y, int ylen)
{
int suf_index = maxlen = maxindex = 0;
int len_suff = xlen + ylen + 1;
char * arr = new char [len_suff + 1]; /* 将X和Y连接到一起 */
strcpy(arr,X);
arr[xlen] = '#';
strcpy(arr + xlen + 1, Y);
for(int i = 0; i < len_suff; ++i) /* 初始化后缀数组 */
{
suff[i] = & arr[i];
}
qsort(suff, len_suff, sizeof(char *), pstrcmp);
for(int i = 0; i < len_suff-1; ++i)
{
int len = comlen_suff(suff[i],suff[i+1]);
if(len > maxlen)
{
maxlen = len;
suf_index = i;
}
}
outputLCS(suff[suf_index]);
}