Advertisement
Retroledeom

Priority Queue

Mar 26th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. PH
  3. 0:00 / 5:00
  4. Learn Priority Queue data structures in 5 minutes 🥇
  5. Bro Code
  6. 870K subscribers
  7. 42K views 1 year ago Java tutorial for beginners ☕
  8. Priority queues data structures and algorithms tutorial example explained
  9.  
  10. #priority #queue #java
  11. 72 Comments
  12. jujuArtz
  13. Add a comment...
  14. @BroCodez
  15. Pinned by Bro Code
  16. @BroCodez
  17. 1 year ago (edited)
  18. import java.util.*;
  19.  
  20.  
  21.  
  22. public class Main{
  23.  
  24.  
  25.  
  26. public static void main(String args[])
  27.  
  28. {
  29.  
  30. //Priority Queue = A FIFO data structure that serves elements
  31.  
  32. // with the highest priorities first
  33.  
  34. // before elements with lower priority
  35.  
  36.  
  37.  
  38. //Strings in default order
  39.  
  40. Queue<String> queue = new PriorityQueue<>();
  41.  
  42.  
  43.  
  44. //Strings in reverse order
  45.  
  46. //Queue<String> queue = new PriorityQueue<>(Collections.reverseOrder());
  47.  
  48.  
  49.  
  50. queue.offer("B");
  51.  
  52. queue.offer("C");
  53.  
  54. queue.offer("A");
  55.  
  56. queue.offer("F");
  57.  
  58. queue.offer("D");
  59.  
  60.  
  61.  
  62. while(!queue.isEmpty()) {
  63.  
  64. System.out.println(queue.poll());
  65.  
  66. }
  67.  
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement