//A Queue is a first-in, first-out(FIFO) data structure
//The offer method inserts an element
//The peek() methods return the head of the queue
//The poll() methods remove the head of the queue
import java.util.*;
public class HackDefence{
public static void main(String[] args){
PriorityQueue<String> q = new PriorityQueue<String>();
q.offer("First");
q.offer("Second");
q.offer("Third");
System.out.printf("%s",q);
System.out.println();
System.out.printf("%s", q.peek());
System.out.println();
q.poll();
System.out.printf("%s", q);
}
}
OUTPUT:
//The offer method inserts an element
//The peek() methods return the head of the queue
//The poll() methods remove the head of the queue
import java.util.*;
public class HackDefence{
public static void main(String[] args){
PriorityQueue<String> q = new PriorityQueue<String>();
q.offer("First");
q.offer("Second");
q.offer("Third");
System.out.printf("%s",q);
System.out.println();
System.out.printf("%s", q.peek());
System.out.println();
q.poll();
System.out.printf("%s", q);
}
}
OUTPUT:
Nice Info and share :)
ReplyDelete