Last active
May 29, 2019 18:44
-
-
Save davidinga/7282413a8724930a367398900cc21613 to your computer and use it in GitHub Desktop.
Stack with Array 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 Stack<Element> { | |
fileprivate var array = [Element]() | |
public var isEmpty: Bool { | |
return array.isEmpty | |
} | |
public var count: Int { | |
return array.count | |
} | |
public func peek() -> Element? { | |
return array.last | |
} | |
public mutating func push(_ element: Element) { | |
array.append(element) | |
} | |
public mutating func pop() -> Element? { | |
return array.popLast() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment