Created
May 29, 2019 18:44
-
-
Save davidinga/7fe74910fd23e874161aa16b044decf5 to your computer and use it in GitHub Desktop.
Stack 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
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