#include "stdio.h"
#define LEN1 7
#define LEN2 6
void LCSfind(int m,int n,char x[LEN1],char y[LEN2],int c[LEN2+1][LEN1+1],int b[LEN2+1][LEN1+1])
{
int i,j;
for(i=0;i<=m;i++) c[i][0]=0,b[i][0]=0;
for(i=1;i<=n;i++) c[0][i]=0,b[0][i]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(x[i]==y[j])
{
c[i][j]=c[i-1][j-1]+1;
b[i][j]=1;
}
else if(c[i-1][j]>=c[i][j-1])
{
c[i][j]=c[i-1][j];
b[i][j]=2;
}
else
{
c[i][j]=c[i][j-1];
b[i][j]=3;
}
}
}
void LCSprint(int i,int j,char x[LEN1],char b[LEN2+1][LEN1+1])
{
if(i==0||j==0) return;
if(b[i][j]==1)
{
LCS(i-1,j-1,x,b);
printf("%d",x[i-1]);
}
else if(b[i][j]==2)
LCS(i-1,j,x,b);
else
LCS(i,j-1,x,b);
}
void main()
{
char x[]={'A','B','C','B','D','A','B'};
char y[]={'B','D','C','A','B','A'};
int c[LEN2+1][LEN1+1],b[LEN2+1][LEN1+1];
int m=LEN1,n=LEN2;
LCSfind(m,n,x,y,c,b);
LCSprint(m,n,x,b);
}
源程序如下所示,编译时有一处警告:
LCSprint(m,n,x,b); (既主函数最后一句出现)
Warning : Suspicious pointer conversion in function main
不知道要怎么改,T_T,请求哥哥姐姐们帮我改下,谢谢啦~~