45 int w,
int s,
int a,
int d)
47 int len1 = strlen(string1), len2 = strlen(string2);
48 int *row0 =
malloc(
sizeof(
int) * (len2 + 1));
49 int *row1 =
malloc(
sizeof(
int) * (len2 + 1));
50 int *row2 =
malloc(
sizeof(
int) * (len2 + 1));
53 for (j = 0; j <= len2; j++)
55 for (i = 0; i < len1; i++) {
58 row2[0] = (i + 1) * d;
59 for (j = 0; j < len2; j++) {
61 row2[j + 1] = row1[j] + s * (string1[i] != string2[j]);
63 if (i > 0 && j > 0 && string1[i - 1] == string2[j] &&
64 string1[i] == string2[j - 1] &&
65 row2[j + 1] > row0[j - 1] + w)
66 row2[j + 1] = row0[j - 1] + w;
68 if (row2[j + 1] > row1[j + 1] + d)
69 row2[j + 1] = row1[j + 1] + d;
71 if (row2[j + 1] > row2[j] + a)
72 row2[j + 1] = row2[j] + a;
int levenshtein(const char *string1, const char *string2, int w, int s, int a, int d)