Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Created February 9, 2020 07:39
Show Gist options
  • Select an option

  • Save AppleCEO/926b8d5cc34b380ad0bd56c078526dd0 to your computer and use it in GitHub Desktop.

Select an option

Save AppleCEO/926b8d5cc34b380ad0bd56c078526dd0 to your computer and use it in GitHub Desktop.
struct Stack {
private var array = [Int]()
mutating func push(element: Int) {
array.append(element)
}
mutating func pop() -> Int? {
return array.popLast()
}
}
var stack = Stack()
stack.push(element: 1)
stack.push(element: 2)
stack.push(element: 3)
stack.pop() == 3
stack.pop() == 2
stack.pop() == 1
stack.pop() == nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment