|
@@ -18,9 +18,6 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
|
|
|
private ConsList<E> current = ConsListImpl.this;
|
|
|
@Override
|
|
|
public boolean hasNext() {
|
|
|
- if(current == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
return !current.isEmpty();
|
|
|
}
|
|
|
|
|
@@ -44,9 +41,7 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
|
|
|
}
|
|
|
|
|
|
private ConsList<E> appendRec(E e, ConsList<E> list) {
|
|
|
- if(list == null) {
|
|
|
- return new ConsListImpl<>(e, null);
|
|
|
- } else if(list.isEmpty()) {
|
|
|
+ if(list.isEmpty()) {
|
|
|
return new ConsListImpl<>(e, list);
|
|
|
}
|
|
|
return new ConsListImpl<>(list.car(), this.appendRec(e, list.cdr()));
|
|
@@ -82,7 +77,11 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
|
|
|
public String toString() {
|
|
|
String str = "(";
|
|
|
for(E e : this) {
|
|
|
- str += e.toString() + " ";
|
|
|
+ if(e == null) {
|
|
|
+ str += "null ";
|
|
|
+ } else {
|
|
|
+ str += e.toString() + " ";
|
|
|
+ }
|
|
|
}
|
|
|
return str.trim() + ")";
|
|
|
}
|