Created
May 29, 2019 23:34
-
-
Save davidinga/888687943536693bad51b5fbb4947e0e to your computer and use it in GitHub Desktop.
Queue with Linked List implementation
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
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