Beruflich Dokumente
Kultur Dokumente
IList<T> items;
IListIterator(IList<T> items) {
this.items = items;
}
public boolean hasNext() {
...
}
public T next() {
...
}
public void remove() {
throw new UnsupportedOperationException("Don't do this!");
}
}
As with the previous iterator, we have a next item when we are currently pointing at aCons node:
// In IListIterator
public boolean hasNext() {
return this.items.isCons();
}
And likewise we can return the item in the current Cons for our next value. To update the iterator, we advance items to refer to the current Cons’s rest:
// In IListIterator
public T next() {
ConsList<T> itemsAsCons = this.items.asCons();
T answer = itemsAsCons.first;
this.items = itemsAsCons.rest;
return answer;
}
String name;
IAT mom;
IAT dad;
interface IATVisitor<R> {
R visitUnknown(Unknown unknown);
R visitPerson(Person person);
}
// In Graph
boolean bfs(Vertex from, Vertex to) {
return searchHelp(from, to, new Queue<Vertex>());
}
boolean dfs(Vertex from, Vertex to) {
return searchHelp(from, to, new Stack<Vertex>());
}
boolean searchHelp(Vertex from, Vertex to, ICollection<Vertex> worklist) {
Deque<Vertex> alreadySeen = new Deque<Vertex>();