- ๋ณ์, ํด๋์ค, ๊ตฌ์กฐ์ฒด ๋ฑ์ ์ ์ธํ ๋, ํด๋น ๊ฐ์ฒด ๋ด๋ถ์์ ์ฌ์ฉํ๋ ํ์
์ ๊ณ ์ ํ์ง ์๊ณ ์์์ ํ์
์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ ๊ฒ
- ์ค์ ์ฌ์ฉํ๋ ์์ ์ ์ฌ์ฉํ๋ ํ์
์ ๊ฒฐ์ ํ๋ค.
struct Stack<T> {
private var items: [T] = []
mutating func push(_ item: T) {
items.append(item)
}
mutating func pop() -> T? {
return items.popLast()
}
func peek() -> T? {
return items.last
}
var isEmpty: Bool {
return items.isEmpty
}
var count: Int {
return items.count
}
}
// Int ํ์
์ ์คํ ์์ฑ
var intStack = Stack<Int>()
intStack.push(1)
intStack.push(2)
intStack.push(3)