Generics
Generic & Mutating (diff in Any)
class Stack<T> {
var arr: [T] = []
func push(_ item: T) {
arr.append(item)
}
func remove(at index: Int) {
arr.remove(at: index)
}
}
let stack_1 = Stack<Int>()
stack_1.push(5)
stack_1.remove(at: 0)
Generic & Mutating (diff in Any)
class Stack<T> {
var arr: [T] = []
func push(_ item: T) {
arr.append(item)
}
func remove(at index: Int) {
arr.remove(at: index)
}
}
let stack_1 = Stack<Int>()
stack_1.push(5)
stack_1.remove(at: 0)
Comments
Post a Comment