Files
hello-algo/ru/codes/java/chapter_stack_and_queue/queue.java
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

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