mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 02:43:41 +08:00
* Review the EN heading format. * Fix pythontutor headings. * Fix pythontutor headings. * bug fixes * Fix headings in **/summary.md * Revisit the CN-to-EN translation for Python code using Claude-4.5 * Revisit the CN-to-EN translation for Java code using Claude-4.5 * Revisit the CN-to-EN translation for Cpp code using Claude-4.5. * Fix the dictionary. * Fix cpp code translation for the multipart strings. * Translate Go code to English. * Update workflows to test EN code. * Add EN translation for C. * Add EN translation for CSharp. * Add EN translation for Swift. * Trigger the CI check. * Revert. * Update en/hash_map.md * Add the EN version of Dart code. * Add the EN version of Kotlin code. * Add missing code files. * Add the EN version of JavaScript code. * Add the EN version of TypeScript code. * Fix the workflows. * Add the EN version of Ruby code. * Add the EN version of Rust code. * Update the CI check for the English version code. * Update Python CI check. * Fix cmakelists for en/C code. * Fix Ruby comments
41 lines
1.1 KiB
Swift
41 lines
1.1 KiB
Swift
/**
|
|
* File: queue.swift
|
|
* Created Time: 2023-01-11
|
|
* Author: nuomi1 (nuomi1@qq.com)
|
|
*/
|
|
|
|
@main
|
|
enum Queue {
|
|
/* Driver Code */
|
|
static func main() {
|
|
/* Access front of the queue element */
|
|
// Swift has no built-in queue class, can use Array as queue
|
|
var queue: [Int] = []
|
|
|
|
/* Elements enqueue */
|
|
queue.append(1)
|
|
queue.append(3)
|
|
queue.append(2)
|
|
queue.append(5)
|
|
queue.append(4)
|
|
print("Queue queue = \(queue)")
|
|
|
|
/* Return list for printing */
|
|
let peek = queue.first!
|
|
print("Front element peek = \(peek)")
|
|
|
|
/* Element dequeue */
|
|
// When simulating with Array, pop complexity is O(n)
|
|
let pool = queue.removeFirst()
|
|
print("Dequeue element pop = \(pool), after dequeue queue = \(queue)")
|
|
|
|
/* Get the length of the queue */
|
|
let size = queue.count
|
|
print("Queue length size = \(size)")
|
|
|
|
/* Check if the queue is empty */
|
|
let isEmpty = queue.isEmpty
|
|
print("Is queue empty = \(isEmpty)")
|
|
}
|
|
}
|