TIL41 ✨

YaR LabΒ·2023λ…„ 6μ›” 19일
0

TIL✨

λͺ©λ‘ 보기
30/136
post-thumbnail

πŸ—“οΈ23.06.19

dequeue

func dequeue<T>(from array: inout [T]) -> T? {
    guard !array.isEmpty else {
        return nil
    }
    
    return array.removeFirst()
}
var queue = [1, 2, 3, 4, 5]

if let dequeuedElement = dequeue(from: &queue) {
    print("Dequeued element: \(dequeuedElement)") // 좜λ ₯: Dequeued element: 1
}

print("Remaining queue: \(queue)") // 좜λ ₯: Remaining queue: [2, 3, 4, 5]

μ΅œμ†Ÿκ°’ μ°ΎκΈ°

0개의 λŒ“κΈ€