mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-04 03:14:09 +08:00
translation: Add Python and Java code for EN version (#1345)
* Add the intial translation of code of all the languages * test * revert * Remove * Add Python and Java code for EN version
This commit is contained in:
40
en/codes/java/chapter_stack_and_queue/queue.java
Normal file
40
en/codes/java/chapter_stack_and_queue/queue.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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) {
|
||||
/* Initialize queue */
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
|
||||
/* Element enqueue */
|
||||
queue.offer(1);
|
||||
queue.offer(3);
|
||||
queue.offer(2);
|
||||
queue.offer(5);
|
||||
queue.offer(4);
|
||||
System.out.println("Queue queue = " + queue);
|
||||
|
||||
/* Access front element */
|
||||
int peek = queue.peek();
|
||||
System.out.println("Front element peek = " + peek);
|
||||
|
||||
/* Element dequeue */
|
||||
int pop = queue.poll();
|
||||
System.out.println("Dequeued element = " + pop + ", after dequeuing" + queue);
|
||||
|
||||
/* Get the length of the queue */
|
||||
int size = queue.size();
|
||||
System.out.println("Length of the queue size = " + size);
|
||||
|
||||
/* Determine if the queue is empty */
|
||||
boolean isEmpty = queue.isEmpty();
|
||||
System.out.println("Is the queue empty = " + isEmpty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user