hello everyone
So today’s coding session wasn’t normal because Aarav wanted everything to be first, Rahul wanted only high-priority items, and I (Daksh) just watched them fight while writing the program And that’s exactly how we ended up learning Priority Queue using Linked List.
What’s Going On Here?
A Priority Queue is like real life the most important (or smallest numbered priority) thing gets done first. Not like Aarav, who thinks he should always go first even when his priority is 100 .
We use a linked list so that:
-
each node stores a value and its priority,
-
new elements are inserted in sorted priority order,
-
deletion always removes the highest priority element,
-
and the list grows easily using
malloc.
How It Works
Rahul took over insertions he made sure every new element was placed exactly at the right priority spot, and honestly he was too strict about it “Low priority? Back of the line!” he kept saying. Aarav handled deletions and of course, he only removed the one with the highest priority, bragging every time he “deleted responsibly” I (Daksh) kept displaying the queue after each operation, like: “Here’s your Priority Queue, sorted and drama-free unlike our group decisions.” With all three of us, the priority queue behaved perfectly more perfectly than our plans ever do
Code:
| ← Previous | 🏠 Homepage | Next Chapter → |
No comments:
Post a Comment