import java.util.*;
public class InnerClassExample<E> {
	E[] data;
	int size;
	
	public InnerClassExample() {
		data = (E[]) new Object[1000];
		size = 0;
	}
	
	public void add(E e) {
		data[size] = e;
		size += 1;
	}
	
	public WeakIterator<E> iterator() {
		return new myIterator();
	}
	
	public class myIterator implements WeakIterator<E> {
		int current;
		
		protected myIterator() {
			current = -1;
		}
		
		public E next() throws NoSuchElementException {
			if (current == size-1) 
				throw new NoSuchElementException("at end of list");
			else {
				current += 1;
				return data[current];
			}
		}
		
		public boolean hasNext() {
			return !(current == size-1);
		}
	}
	
	public static void main(String[] args) {
		InnerClassExample<Integer>L = new InnerClassExample<Integer>();
		for (int i = 0; i < 10; i++)
			L.add(3*i+5);
		WeakIterator<Integer> it = L.iterator();
		while (it.hasNext())
			System.out.println(it.next());
	}
}
