mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-18 01:37:17 +08:00
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:
39
ja/codes/swift/chapter_stack_and_queue/stack.swift
Normal file
39
ja/codes/swift/chapter_stack_and_queue/stack.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* File: stack.swift
|
||||
* Created Time: 2023-01-09
|
||||
* Author: nuomi1 (nuomi1@qq.com)
|
||||
*/
|
||||
|
||||
@main
|
||||
enum Stack {
|
||||
/* Driver Code */
|
||||
static func main() {
|
||||
/* スタックを初期化 */
|
||||
// Swift には組み込みのスタッククラスがないため、Array をスタックとして使う
|
||||
var stack: [Int] = []
|
||||
|
||||
/* 要素をプッシュ */
|
||||
stack.append(1)
|
||||
stack.append(3)
|
||||
stack.append(2)
|
||||
stack.append(5)
|
||||
stack.append(4)
|
||||
print("スタック stack = \(stack)")
|
||||
|
||||
/* スタックトップの要素にアクセス */
|
||||
let peek = stack.last!
|
||||
print("スタックトップ要素 peek = \(peek)")
|
||||
|
||||
/* 要素をポップ */
|
||||
let pop = stack.removeLast()
|
||||
print("ポップした要素 pop = \(pop)、ポップ後の stack = \(stack)")
|
||||
|
||||
/* スタックの長さを取得 */
|
||||
let size = stack.count
|
||||
print("スタックの長さ size = \(size)")
|
||||
|
||||
/* 空かどうかを判定 */
|
||||
let isEmpty = stack.isEmpty
|
||||
print("スタックが空かどうか = \(isEmpty)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user