Tuesday, October 11, 2011
class DList
{
DNode prev(DNode current)
{
return current.prev;
}
}
main()
{
DNode j;
DList dl;
//...
j.getPrev(); // no! Don't do that!
dl.prev(j);
dl.replace(j, 6);
}
class ArrayBasedStack<T> implements Iterable<T>
{
/// ...
Iterator<T> iterator() { return new ArrayBasedStackIterator<T>(); }
}
class ArrayBasedStackIterator<T> implement Iterator<T>
{
boolean hasNext() { return false; }
Iterator<T> next() { return null; }
}
for (Iterator<T> it = L.iterator(), it.next(); it.hasNext() == true;
it.next())
List<Integer> values;
// ... statements that create a new // values list and int sum = 0;
Iterator<Integer> it = values.iterator();
for (Integer i = it.next(); it.hasNext(); it.next())
{ sum += i; }
class ArrayBasedStack<E> implements java.util.Queue<E>
{
public void push(E o) { A[top++]=o; }
public boolean add(E o)
{
push(o);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment