Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PH
- 0:00 / 5:00
- Learn Priority Queue data structures in 5 minutes 🥇
- Bro Code
- 870K subscribers
- 42K views 1 year ago Java tutorial for beginners ☕
- Priority queues data structures and algorithms tutorial example explained
- #priority #queue #java
- 72 Comments
- jujuArtz
- Add a comment...
- @BroCodez
- Pinned by Bro Code
- @BroCodez
- 1 year ago (edited)
- import java.util.*;
- public class Main{
- public static void main(String args[])
- {
- //Priority Queue = A FIFO data structure that serves elements
- // with the highest priorities first
- // before elements with lower priority
- //Strings in default order
- Queue<String> queue = new PriorityQueue<>();
- //Strings in reverse order
- //Queue<String> queue = new PriorityQueue<>(Collections.reverseOrder());
- queue.offer("B");
- queue.offer("C");
- queue.offer("A");
- queue.offer("F");
- queue.offer("D");
- while(!queue.isEmpty()) {
- System.out.println(queue.poll());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement