Matsushita's Blog

281. Zigzag Iterator : Past Google Coding Interview


How to Solve

By using Iterator and Queue, I can solve this problem.


ListIterator (Java Platform SE 8 )

An iterator for lists that allows the programmer to traverse the list in either direction, modify the during iteration, and obtain the iterator's current position in the list. A ListIterator has no current element ; its cursor postition always lies between that would be returned by a call to next()

Implement a Zigzag Iterator by using a Queue

In this problem case, We have to return the number of the two list alternately. So, to add the list into the Queue or to remove list from the Queue, We can return the number alternately.

Source Code