Skip to content

Instantly share code, notes, and snippets.

@kalub92
Created March 12, 2018 23:31
Show Gist options
  • Save kalub92/563f7fb67ead7dfa5f75a20a171bc30e to your computer and use it in GitHub Desktop.
Save kalub92/563f7fb67ead7dfa5f75a20a171bc30e to your computer and use it in GitHub Desktop.
import Foundation
struct Stack {
private var items: [String] = []
func peek() -> String {
guard let topElement = items.first else { fatalError("This stack is empty.") }
return topElement
}
mutating func pop() -> String {
return items.removeFirst()
}
mutating func push(_ element: String) {
items.insert(element, at: 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment