Created
February 9, 2020 07:39
-
-
Save AppleCEO/926b8d5cc34b380ad0bd56c078526dd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
| 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