@param: vecs: a list of 1d vectors
| 1 | # zigzag iterator but for undifined numbers of vecs |
| 2 | |
| 3 | class ZigzagIterator2: |
| 4 | """ |
| 5 | @param: vecs: a list of 1d vectors |
| 6 | """ |
| 7 | |
| 8 | def __init__(self, vecs): |
| 9 | # do intialization if necessary |
| 10 | self.vecs = vecs |
| 11 | self.queue = [] |
| 12 | for i in range(len(vecs)): |
| 13 | if len(vecs[i]) > 0: |
| 14 | self.queue.append((i, 0)) |
| 15 | """ |
| 16 | @return: An integer |
| 17 | """ |
| 18 | |
| 19 | def _next(self): |
| 20 | row, col = self.queue.pop(0) |
| 21 | |
| 22 | if col + 1 < len(self.vecs[row]): |
| 23 | self.queue.append((row, col+1)) |
| 24 | return self.vecs[row][col] |
| 25 | """ |
| 26 | @return: True if has next |
| 27 | """ |
| 28 | |
| 29 | def hasNext(self): |
| 30 | return len(self.queue) != 0 |
nothing calls this directly
no outgoing calls
no test coverage detected