• ๋ณ€์ˆ˜, ํด๋ž˜์Šค, ๊ตฌ์กฐ์ฒด ๋“ฑ์„ ์„ ์–ธํ•  ๋•Œ, ํ•ด๋‹น ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํƒ€์ž…์„ ๊ณ ์ •ํ•˜์ง€ ์•Š๊ณ  ์ž„์˜์˜ ํƒ€์ž…์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ
  • ์‹ค์ œ ์‚ฌ์šฉํ•˜๋Š” ์‹œ์ ์— ์‚ฌ์šฉํ•˜๋Š” ํƒ€์ž…์„ ๊ฒฐ์ •ํ•œ๋‹ค.
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)