Skip to content

Instantly share code, notes, and snippets.

@davidinga
Created May 29, 2019 23:34
Show Gist options
  • Save davidinga/888687943536693bad51b5fbb4947e0e to your computer and use it in GitHub Desktop.
Save davidinga/888687943536693bad51b5fbb4947e0e to your computer and use it in GitHub Desktop.
Queue with Linked List implementation
public struct Queue<Element> {
fileprivate let queue = SinglyLinkedList<Element>()
var isEmpty: Bool {
return queue.isEmpty
}
var count: Int {
return queue.count
}
mutating func enqueue(_ element: Element) {
queue.append(element)
}
mutating func dequeue() -> SinglyLinkedListNode<Element>? {
return queue.remove(node: queue.head!)
}
func peek() -> SinglyLinkedListNode<Element>? {
return queue.head!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment