The assignment this week is to spend some time creating a working implementation
ID: 668599 • Letter: T
Question
The assignment this week is to spend some time creating a working implementation of the MixedFlatteningList interface.
Submit three .java files: The interface, your implementation, and any test code that you wrote.
Submit a short description of your process and the results in a .txt file.
public interface MixedFlatteningList {
public MixedFlatteningList get(int index);
public boolean isInt();
public boolean isString();
public boolean isCompound();
public int getInt();
public String getString();
public void clear();
public void add(int value);
public void add(String value);
public void add(MixedFlatteningList value);
public void set(int value, int index);
public void set(String value, int index);
public void set(MixedFlatteningList value, int index);
public String toString();
public void flatten();
public MixedFlatteningList toFlattened();
public boolean isFlat();
public MixedFlatteningList clone();
}
Explanation / Answer
some of MixedFlatteningList Programm : public class FlattenIterator implements Iterator { private final Stack iteratorStack; private Object next; public FlattenIterator(List list) { if (list == null) { throw new NullPointerException(); } iteratorStack = new Stack(); iteratorStack.push(list.iterator()); } public void remove() { /* Not implemented */ } private void moveToNext() { if ((next == null) && !iteratorStack.empty()) { if (iteratorStack.peek().hasNext()) { final Object next = iteratorStack.peek().next(); if (next instanceof Iterator) { iteratorStack.push((Iterator) next); moveToNext(); } else if (next instanceof Iterable) { iteratorStack.push(((Iterable) next).iterator()); moveToNext(); } else if (next instanceof Array) { iteratorStack.push(Arrays.asList((Array) next).iterator()); moveToNext(); } else { this.next = next; } } else { iteratorStack.pop(); moveToNext(); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.