Files
hello-algo/ru/codes/java/chapter_stack_and_queue/queue.java
T
Yudong JinandClaude Opus 5.5 ded7ddc635 Revert the runnable-snippets batches to the #2033 state (#2038)
Reverts #2034, #2035, #2036 and #2037. The work will return in a single
reviewed PR that is completed before it merges. The tree equals 8c96e2f30
(#2033).

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

41 lines
1.3 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) {
/* Инициализация очереди */
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 = " + pop + ", queue после извлечения = " + queue);
/* Получение длины очереди */
int size = queue.size();
System.out.println("Длина очереди size = " + size);
/* Проверка, пуста ли очередь */
boolean isEmpty = queue.isEmpty();
System.out.println("Пуста ли очередь = " + isEmpty);
}
}