Last active
March 29, 2018 10:00
-
-
Save Abhishek9634/ff3bd2d779fb1d333fcbaaed867f267b to your computer and use it in GitHub Desktop.
This file contains 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 Foundation | |
class Queue<T: CustomStringConvertible>: CustomStringConvertible { | |
fileprivate var array: [T] = [] | |
func dequeue() -> T? { | |
let dequeueItem = self.array.removeFirst() | |
print("DEQUEUE ITEM : \(dequeueItem.description)") | |
return dequeueItem | |
} | |
func enqueue(item: T) { | |
print("ENQUEUE ITEM : \(item.description)") | |
array.append(item) | |
} | |
var isEmpty: Bool { | |
return self.array.isEmpty | |
} | |
var count: Int { | |
return self.array.count | |
} | |
var description: String { | |
let top = "### QUEUE ###\n\n" | |
let bottom = "\n\n#############\n" | |
let elements = self.array.map { $0.description }.joined(separator: " ") | |
return top + elements + bottom | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment