Skip to content

Instantly share code, notes, and snippets.

@davidinga
Created May 29, 2019 18:44
Show Gist options
  • Save davidinga/7fe74910fd23e874161aa16b044decf5 to your computer and use it in GitHub Desktop.
Save davidinga/7fe74910fd23e874161aa16b044decf5 to your computer and use it in GitHub Desktop.
Stack with Linked List implementation
struct StackWithLinkedList<Element> {
let stack = DoublyLinkedList<Element>()
mutating func push(_ element: Element) {
stack.append(element)
}
mutating func pop() -> DoublyLinkedListNode<Element>? {
return stack.remove(node: stack.tail!)
}
func peek() -> DoublyLinkedListNode<Element>? {
return stack.tail
}
var isEmpty: Bool {
return stack.isEmpty
}
var count: Int {
return stack.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment