Files
hello-algo/ja/codes/java/chapter_stack_and_queue/queue.java
T
Yudong JinandClaude Opus 5.5 eeb8a3b790 Cite demo-source regions from the remaining A-class snippets (batch 2) (#2035)
Migrate init_array, hash_map_operations, hash_map_traversal,
queue_operations, deque_operations and insert_remove_node: zh and ru
demo sources gain region markers and the snippets' comments, en, ja and
ko are regenerated from reviewed translations, zh-hant via OpenCC. 70
blocks become region references; builtin_hash and five blocks without
reviewed translations stay literal.

The Java, Kotlin and Rust deque demos follow the book's order, and a few
demo comments and typos are aligned with the snippets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-16 04:23:45 +08:00

53 lines
1.5 KiB
Java

/**
* File: queue.java
* Created Time: 2022-11-25
* Author: krahets ([email protected])
*/
package chapter_stack_and_queue;
import java.util.*;
public class queue {
public static void main(String[] args) {
// [region]{init_queue}
/* キューを初期化する */
Queue<Integer> queue = new LinkedList<>();
// [endregion]{init_queue}
// [region]{push}
/* 要素をエンキューする */
queue.offer(1);
queue.offer(3);
queue.offer(2);
queue.offer(5);
queue.offer(4);
// [endregion]{push}
System.out.println("キュー queue = " + queue);
// [region]{peek}
/* キューの先頭要素にアクセス */
int peek = queue.peek();
// [endregion]{peek}
System.out.println("キューの先頭要素 peek = " + peek);
// [region]{pop}
/* 要素をデキューする */
int pop = queue.poll();
// [endregion]{pop}
System.out.println("デキューした要素 pop = " + pop + "、デキュー後 queue = " + queue);
// [region]{size}
/* キューの長さを取得 */
int size = queue.size();
// [endregion]{size}
System.out.println("キューの長さ size = " + size);
// [region]{is_empty}
/* キューが空か判定 */
boolean isEmpty = queue.isEmpty();
// [endregion]{is_empty}
System.out.println("キューは空か = " + isEmpty);
}
}