Files
hello-algo/en/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.1 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) {
/* Initialize the queue */
Queue<Integer> queue = new LinkedList<>();
/* Enqueue elements */
queue.offer(1);
queue.offer(3);
queue.offer(2);
queue.offer(5);
queue.offer(4);
System.out.println("Queue queue = " + queue);
/* Access the front element */
int peek = queue.peek();
System.out.println("Front element peek = " + peek);
/* Dequeue an element */
int pop = queue.poll();
System.out.println("Dequeued element pop = " + pop + ", after dequeuing, queue = " + queue);
/* Get the queue size */
int size = queue.size();
System.out.println("Queue size = " + size);
/* Check whether the queue is empty */
boolean isEmpty = queue.isEmpty();
System.out.println("Is the queue empty = " + isEmpty);
}
}