Subato

Resource Files

Spliterator Loop für verkettete Listen

Geben Sie den einfach verketteten Listen die Möglichkeit, einen Spliterator zu generieren, der über alle Listenelemente iteriert.

Implementieren Sie die Methode trySplit so, dass, wenn noch mehr als fünf Iterationen anliegen, die ersten 5 Iterationen auf den neuen Spliterator übertragen werden.


package name.panitz.util; public class LL<A>{ final private A hd; final private LL<A> tl; public boolean isEmpty(){ return hd==null&&tl==null; } public LL(A hd, LL<A> tl) { this.hd = hd; this.tl = tl; } public LL() { this(null,null); } public A get(int i) { return i==0?hd:tl.get(i-1); } public Loop<A> getSpliterator(){ return new LLLoop(); } private class LLLoop implements Loop<A>{ LL<A> c = LL.this; //TODO Implementieren Sie: test, step, get, trysplit public boolean test(){ return false; } public void step(){ //TODO } public A get(){ //TODO return null; } } @SuppressWarnings("unchecked") static <A> LL<A> create(A... es){ LL<A> result = new LL<A>(); for (int i=es.length-1;i>=0;i--){ result = new LL<A>(es[i],result); } return result; } }
java
You are not logged in and therefore you cannot submit a solution.