
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
None | size: 0.69 KB | hits: 9 | expires: Never
public class Listb implements List{
Object element;
Listb tail;
public Listb() {
element = null;
tail = null;
}
private Listb(Object o, Listb t) {
element = o;
tail = t;
}
public boolean isEmpty() {
return element == null && tail == null;
}
public Object head() {
return element;
}
public List tail() {
return tail;
}
public List cons(Object o) {
Listb newList = new Listb(o, this);
return newList;
}
public int len() {
int i = 0;
Listb lp = this;
while (!lp.isEmpty()) {
i++;
lp = lp.tail;
}
return i;
}
public int rlen() {
if (isEmpty())
return 0;
else
return 1 + tail.rlen();
}
}