Java Tutorial #51 - Java PriorityQueue Class with Examples (Collections)

  Рет қаралды 17,553

Programming For Beginners

Programming For Beginners

Күн бұрын

Пікірлер: 18
@sravanipudu
@sravanipudu 5 ай бұрын
I am very confused about this concept.. now it's all cleared my doubts .. thank you
@programmingforbeginners7392
@programmingforbeginners7392 5 ай бұрын
Glad to hear that
@MahaDev-cx1ij
@MahaDev-cx1ij 5 ай бұрын
Very impressive and wow presentation
@programmingforbeginners7392
@programmingforbeginners7392 5 ай бұрын
Thank you 😊
@paarthiban8452
@paarthiban8452 Жыл бұрын
At last I understood the algorithm behind the priority queue...really nice work buddy.👌
@programmingforbeginners7392
@programmingforbeginners7392 Жыл бұрын
Thank you so much.. please share with your friends and subscribe to the channel 🙂👍
@jeyanthan360
@jeyanthan360 Жыл бұрын
For a capacity-constrained queue, the difference between add() and offer() methods are, add() always returns true and throws an exception if it can't add the element, whereas offer() is allowed to return false if it can't add the element.
@thesquarefish
@thesquarefish Жыл бұрын
Don't know if you'll see this message but why would anyone use add() over offer() if add() might error and offer() won't?
@jeyanthan360
@jeyanthan360 Жыл бұрын
@@thesquarefish if you know that the queue has enough capacity to hold the element you want to add, it is generally better to use the add() method. On the other hand, if you are not sure whether the queue has enough capacity or not, or if you want to handle queue overflow gracefully, you can use the offer() method. And actually add() method was created first . After sometimes, from the problem faced by the add() ,offer() has been created. So most text books are using the old methods as an example for adding elements in a priority queue, these youtube videos are also teaching in traditional bookish way. But offer() is good compared to add() we can use that too, totally our choice.
@thesquarefish
@thesquarefish Жыл бұрын
@@jeyanthan360 But from a purely functional standpoint, offer() is always equal to or better than add()?
@jeyanthan360
@jeyanthan360 Жыл бұрын
@@thesquarefish Yessss u r Right
@thesquarefish
@thesquarefish Жыл бұрын
@@jeyanthan360 Ok thank u for answering
@ACUCSPRADEEPB-up9ne
@ACUCSPRADEEPB-up9ne 2 жыл бұрын
Wow 👍
@programmingforbeginners7392
@programmingforbeginners7392 2 жыл бұрын
Thanks 👍
@nishikantmandaokar9353
@nishikantmandaokar9353 Жыл бұрын
You r good.. but lil bit more knowledge is there then it will be good
@programmingforbeginners7392
@programmingforbeginners7392 Жыл бұрын
Ok
@2412Anand
@2412Anand 2 ай бұрын
why it is 1 3 2 4 why not 1 2 3 4
@ankitkulhade9410
@ankitkulhade9410 2 ай бұрын
When you print the PriorityQueue directly using System.out.println(pq);, it does not sort the elements for display. The order you see is simply how the elements are organized in the heap. Therefore, the output may look like [1, 3, 2, 11, 21, 14, 4, 31], which does not represent a sorted order. Continuously poll elements from the PriorityQueue until it's empty. This will give you the elements in sorted order:
Java Tutorial #52 - Java Deque Interface with Examples (Collections)
8:11
Programming For Beginners
Рет қаралды 7 М.
Priority Queue Explained | Min and Max Heap | Custom Comparator
23:19
Daily Code Buffer
Рет қаралды 23 М.
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 112 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
Java Tutorial #55 - Java Map Interface with Examples (Map Data Structure)
9:38
Programming For Beginners
Рет қаралды 1 М.
Priority Queue Introduction
13:18
WilliamFiset
Рет қаралды 474 М.
Java Tutorial #75 - Java File Input Stream Class Examples (File Handling)
9:56
Programming For Beginners
Рет қаралды 3,1 М.
Java Tutorial #50 - Java Queue Interface with Examples (Collections)
8:07
Programming For Beginners
Рет қаралды 11 М.
#28 - What is PriorityQueue in Java with Examples (using Comparator)
15:38
Naveen AutomationLabs
Рет қаралды 18 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
#95 Comparator vs Comparable in Java
15:43
Telusko
Рет қаралды 207 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
Java Tutorial #57 - Java Linked HashMap Class with Examples (Map Data Structure)
10:39
Programming For Beginners
Рет қаралды 1,3 М.
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 112 МЛН