Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Stack<T> {
- private var stack: [T]
- init()
- {
- stack = [T]()
- }
- mutating func push(val: T)
- {
- stack.append(val)
- }
- mutating func pop() -> T
- {
- return stack.removeLast()
- }
- var isEmpty: Bool {
- return stack.isEmpty
- }
- var count : Int {
- return stack.count
- }
- }
- // Int icin
- var stackInt = Stack<Int>()
- stackInt.push(val: 10)
- stackInt.push(val: 20)
- stackInt.push(val: 30)
- while !stackInt.isEmpty {
- print(stackInt.pop())
- }
- // String Icin
- var stackString = Stack<String>()
- stackString.push(val: "Kerem")
- stackString.push(val: "Swift")
- stackString.push(val: "Python")
- while !stackString.isEmpty {
- print(stackString.pop())
- }
Add Comment
Please, Sign In to add comment