My issue
it is showing wrong output
My code
import java.util.LinkedList;
import java.util.Queue;
class QueueExample {
public static void main(String[] args) {
// Create a new queue of integers using a LinkedList implementation
Queue<Integer> queue = new LinkedList<>();
// Enqueue elements (adding elements to the queue)
queue.offer(5); // Add the integer 5 to the end of the queue
queue.offer(10); // Add the integer 10 to the end of the queue
queue.offer(15); // Add the integer 15 to the end of the queue
// Dequeue elements (removing elements from the front of the queue)
int frontElement = queue.poll(); // Remove and retrieve the front element (5)
System.out.println("Front Element: " + frontElement); // Print the removed element
// Peek at the front element (view the front element without removing it)
int peekedElement = queue.peek(); // View the front element (10)
System.out.println("Front Element (Peeked): " + peekedElement); // Print the viewed element
// Check if the queue is empty
boolean isEmpty = queue.isEmpty(); // Check if the queue has no elements
System.out.println("Is Queue Empty? " + isEmpty); // Print whether the queue is empty or not
}
}
Learning course: DSA using Java
Problem Link: CodeChef: Practical coding for everyone