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]