public static int CalculateStringDistance(string strA, int pABegin, int pAEnd, string strB, int pBBegin, int pBEnd)
        {
            if (pABegin > pAEnd)
            {
                if (pBBegin > pBEnd)
                {
                    return 0;
                }
                else
                {
                    return pBEnd - pBBegin + 1;
                }
            }

            if (pBBegin > pBEnd)
            {
                if (pABegin > pAEnd)
                {
                    return 0;
                }
                else
                {
                    return pAEnd - pABegin + 1;
                }
            }
            if (strA[pABegin] == strB[pBBegin])
            {
                return CalculateStringDistance(strA, pABegin + 1, pAEnd, strB, pBBegin + 1, pBEnd);
            }
            else
            {
                int t1 = CalculateStringDistance(strA, pABegin, pAEnd, strB, pBBegin + 1, pBEnd);
                int t2 = CalculateStringDistance(strA, pABegin + 1, pAEnd, strB, pBBegin, pBEnd);
                int t3 = CalculateStringDistance(strA, pABegin + 1, pAEnd, strB, pBBegin + 1, pBEnd);
                int minValue = Math.Min(t1, t2);

                return Math.Min(minValue, t3) + 1;
            }
        }

 

posted on 2013-12-12 16:54  higirle  阅读(294)  评论(0编辑  收藏  举报