struct Stack<Element> {
var items = [Element]()
mutating func push(_ item: Element) {
items.append(item)
}
mutating func pop() -> Element? {
return items.popLast()
}
func peek() -> Element? {
return items.last
}
}
var intStack = Stack<Int>()
intStack.push(1)
intStack.push(3)
intStack.push(5)
let top = intStack.peek()!
//top is 5
let first = intStack.pop()!
//first is 5
let second = intStack.pop()!
//second is 3
let third = intStack.pop()!
//third is 1
print("top is \(top)")
print("first is \(first)")
print("second is \(second)")
print("third is \(third)")