Re-translate the Japanese version (#1871)

* Retranslate Japanese docs with GPT-5.4

* Retranslate Japanese code with GPT-5.4
This commit is contained in:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions
@@ -0,0 +1,113 @@
/**
* File: array_queue.swift
* Created Time: 2023-01-11
* Author: nuomi1 (nuomi1@qq.com)
*/
/* */
class ArrayQueue {
private var nums: [Int] //
private var front: Int //
private var _size: Int //
init(capacity: Int) {
//
nums = Array(repeating: 0, count: capacity)
front = 0
_size = 0
}
/* */
func capacity() -> Int {
nums.count
}
/* */
func size() -> Int {
_size
}
/* */
func isEmpty() -> Bool {
size() == 0
}
/* */
func push(num: Int) {
if size() == capacity() {
print("キューがいっぱいです")
return
}
// + 1
// rear
let rear = (front + size()) % capacity()
// num
nums[rear] = num
_size += 1
}
/* */
@discardableResult
func pop() -> Int {
let num = peek()
// 1
front = (front + 1) % capacity()
_size -= 1
return num
}
/* */
func peek() -> Int {
if isEmpty() {
fatalError("キューが空です")
}
return nums[front]
}
/* */
func toArray() -> [Int] {
//
(front ..< front + size()).map { nums[$0 % capacity()] }
}
}
@main
enum _ArrayQueue {
/* Driver Code */
static func main() {
/* */
let capacity = 10
let queue = ArrayQueue(capacity: capacity)
/* */
queue.push(num: 1)
queue.push(num: 3)
queue.push(num: 2)
queue.push(num: 5)
queue.push(num: 4)
print("キュー queue = \(queue.toArray())")
/* */
let peek = queue.peek()
print("先頭要素 peek = \(peek)")
/* */
let pop = queue.pop()
print("取り出した要素 pop = \(pop),取り出し後 queue = \(queue.toArray())")
/* */
let size = queue.size()
print("キューのサイズ size = \(size)")
/* */
let isEmpty = queue.isEmpty()
print("キューが空かどうか = \(isEmpty)")
/* */
for i in 0 ..< 10 {
queue.push(num: i)
queue.pop()
print("\(i) 回のエンキュー + デキュー後 queue = \(queue.toArray())")
}
}
}