consolidate duplicate Cell classes

This commit is contained in:
Joel Dice
2014-03-24 10:47:37 -06:00
parent 164717056b
commit c2bfba92f0
3 changed files with 23 additions and 53 deletions

View File

@ -31,4 +31,24 @@ public class Cell <T> {
sb.append(")");
return sb.toString();
}
public static <Car> Cell<Car> cons(Car car, Cell<Car> cdr) {
return new Cell(car, cdr);
}
public static <T> boolean equal(T a, T b) {
return (a == null && b == null) || (a != null && a.equals(b));
}
public static <Car> boolean equal(Cell<Car> a, Cell<Car> b) {
while (a != null) {
if (b == null || (! equal(a.value, b.value))) {
return false;
}
a = a.next;
b = b.next;
}
return b == null;
}
}