1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
interface Iterator{
boolean end();
Object current();
void next();
}

public class Sequence{
private Object[] items;
private next = 0;

public Sequence(int size){
items = new Objec[size];
}

public void add(Object x){
if(next&ltitems.length)
items[next++] = x;
}

private class SequenceIterator implements Iterator{
private int i = 0;
public boolean end(){
return i == items.length;
}
public Object current(){
return items[i];
}
public void next(){
if(i&ltitems.length)
i++;
}
}

pubic Iterator iterator(){
return new SequenceIterator();
}
}
文章目录