Capable to k-vector input too:
class ZigzagIterator { int x; int i; int max_x; vector*> l; void moveon() { int oldi= i; i = (i + 1) % l.size(); x += i <= oldi; }public: ZigzagIterator(vector & v1, vector & v2) { i = x = 0; max_x = max(v1.size(), v2.size()); if(v1.size() > 0) l.push_back(&v1); if(v2.size() > 0) l.push_back(&v2); } int next() { int ret = (*l[i])[x]; while(moveon(), x < max_x && l[i]->size() <= x);return ret; return ret; } bool hasNext() { return x < max_x; }};