Posts

Showing posts with the label Queue

Queue

Image
 Queue     Demonstration of queue using linked list in JAVA    package com.company ; import java.util. Queue ; import java.util.LinkedList ; public class Main { public static void main ( String [] args ) { // write your code here Queue < Integer > q = new LinkedList <> (); q . add ( 10 ); q . add ( 1 ); q . add ( 8 ); q . add ( 4 ); q . add ( 7 ); q . add ( 89 ); System . out . println ( "The queue is: " + q ); } } The queue is: [10, 1, 8, 4, 7, 89] Process finished with exit code 0 Show peak of queue    package com.company ; import java.util. Queue ; import java.util.LinkedList ; public class Main { public static void main ( String [] args ) { // write your code here Queue < Integer > q = new LinkedList <> (); q . add ( 6 ); q . add ( 1 ); q . add ( 8 ); q . add ( 4 ); q . add ( 7 ); q . add ( 89 ); System