mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-01 03:24:24 +08:00
* docs: add Japanese documents (`ja/docs`) * docs: add Japanese documents (`ja/codes`) * docs: add Japanese documents * Remove pythontutor blocks in ja/ * Add an empty at the end of each markdown file. * Add the missing figures (use the English version temporarily). * Add index.md for Japanese version. * Add index.html for Japanese version. * Add missing index.assets * Fix backtracking_algorithm.md for Japanese version. * Add avatar_eltociear.jpg. Fix image links on the Japanese landing page. * Add the Japanese banner. --------- Co-authored-by: krahets <krahets@163.com>
40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
/**
|
|
* File: queue.java
|
|
* Created Time: 2022-11-25
|
|
* Author: krahets (krahets@163.com)
|
|
*/
|
|
|
|
package chapter_stack_and_queue;
|
|
|
|
import java.util.*;
|
|
|
|
public class queue {
|
|
public static void main(String[] args) {
|
|
/* キューを初期化 */
|
|
Queue<Integer> queue = new LinkedList<>();
|
|
|
|
/* 要素をエンキュー */
|
|
queue.offer(1);
|
|
queue.offer(3);
|
|
queue.offer(2);
|
|
queue.offer(5);
|
|
queue.offer(4);
|
|
System.out.println("キュー queue = " + queue);
|
|
|
|
/* 先頭要素にアクセス */
|
|
int peek = queue.peek();
|
|
System.out.println("先頭要素 peek = " + peek);
|
|
|
|
/* 要素をデキュー */
|
|
int pop = queue.poll();
|
|
System.out.println("デキューした要素 = " + pop + "、デキュー後 " + queue);
|
|
|
|
/* キューの長さを取得 */
|
|
int size = queue.size();
|
|
System.out.println("キューの長さ size = " + size);
|
|
|
|
/* キューが空かどうかを判定 */
|
|
boolean isEmpty = queue.isEmpty();
|
|
System.out.println("キューが空か = " + isEmpty);
|
|
}
|
|
} |