很笨的把两个list当数组用了 还把list复制了一遍
list自己的iterator就可以了 而且有个很好的方法就是两个iterator每次swap就可以了 不用判断上个是输出的谁
public class ZigzagIterator {
Iterator<Integer> it1, it2;
public ZigzagIterator(List<Integer> v1, List<Integer> v2) {
it1 = v1.iterator();
it2 = v2.iterator();
}
public int next() {
if ( it1.hasNext() ){
Iterator <Integer> temp = it1;
it1 = it2;
it2 = temp;
}
return it2.next();
}
public boolean hasNext() {
return it1.hasNext() || it2.hasNext();
}
}
/**
* Your ZigzagIterator object will be instantiated and called as such:
* ZigzagIterator i = new ZigzagIterator(v1, v2);
* while (i.hasNext()) v[f()] = i.next();
*/