b551cb1bb2f4541f98abb5e28d478e3ce617185d
1 import java
.util
.ArrayList
;
2 import java
.util
.ListIterator
;
5 public static void displayArrayList(ArrayList arrayList
) {
6 ListIterator iter
= arrayList
.listIterator();
8 while (iter
.hasNext()) {
9 System
.out
.println(i
.toString() + " " + iter
.next());
14 public static void computeDistanceFrom(Person personFrom
, ArrayList
<Person
> personArrayList
) {
15 if (!personArrayList
.contains(personFrom
))
16 personArrayList
.add(personFrom
);
17 ListIterator
<Person
> iter
= personArrayList
.listIterator();
18 while (iter
.hasNext()) {
19 Person personCursor
= iter
.next();
20 personCursor
.setDistanceFromReference(personFrom
.distanceTo(personCursor
));
30 private static int minimum(int a
, int b
, int c
) {
31 return Math
.min(Math
.min(a
, b
), c
);
39 public static int computeLevenshteinDistance(CharSequence lhs
, CharSequence rhs
) {
40 int[][] distance
= new int[lhs
.length() + 1][rhs
.length() + 1];
42 for (int i
= 0; i
<= lhs
.length(); i
++)
44 for (int j
= 1; j
<= rhs
.length(); j
++)
47 for (int i
= 1; i
<= lhs
.length(); i
++)
48 for (int j
= 1; j
<= rhs
.length(); j
++)
49 distance
[i
][j
] = minimum(
50 distance
[i
- 1][j
] + 1,
51 distance
[i
][j
- 1] + 1,
52 distance
[i
- 1][j
- 1] + ((lhs
.charAt(i
- 1) == rhs
.charAt(j
- 1)) ?
0 : 1));
54 return distance
[lhs
.length()][rhs
.length()];