Last active
June 29, 2018 15:23
-
-
Save digoreis/8736b748b8812cf01684f50b3ebd0a8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
struct CircularQueueIterator<T>: IteratorProtocol { | |
let queue: [T] | |
private var position = 0 | |
init(queue: [T]) { | |
self.queue = queue | |
} | |
mutating func next() -> T? { | |
let item = queue[position] | |
self.position = ((position + 1) % queue.count) | |
return item | |
} | |
} | |
var arrFruits : CircularQueueIterator<String> = CircularQueueIterator<String>(queue:["Apple", "Orange", "Banana"]) | |
print(arrColor.next()) | |
print(arrColor.next()) | |
print(arrColor.next()) | |
print(arrColor.next()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment