标签:
Capable to k-vector input too:
class ZigzagIterator { int x; int i; int max_x; vector<vector<int>*> l; void moveon() { int oldi= i; i = (i + 1) % l.size(); x += i <= oldi; } public: ZigzagIterator(vector<int>& v1, vector<int>& 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; } };
标签:
原文地址:http://www.cnblogs.com/tonix/p/4809038.html