recategorized by
1,113 views
0 votes
0 votes
On other sources, it is given that we need to assign high priorities to newly inserted element in case of stack otherwise low priority to newly inserted element in case of queue. My doubt here is that shouldn't  stack be implemented with max-heap priority queue and queue with min-heap priority queue keeping above assumption of assigning priorities to newly inserted element?
recategorized by

1 Answer

0 votes
0 votes

If priority of an element is directly proportional to the arrival time of an element then yes you can implement stack with max-heap priority queue and queue with min-heap priority queue.

Since Stack follows LIFO(Last In First Out) order, the greater the arrival time, the greater will be the priority and hence you can emulate LIFO, just by using priorities. Similar logic applies for FIFO data structure queue.

Related questions

0 votes
0 votes
1 answer
1
rahul sharma 5 asked Dec 17, 2016
993 views
How to implement Priority queue using stack?What will be time complexity for Enqueue and Dequeue operations?Edit:- Updated the question clearly
0 votes
0 votes
0 answers
3
srestha asked Dec 22, 2018
600 views
Is priority queue work efficiently with sorted array than unsorted array and heap for insertion and deletion operation? Then why do we apply priority queue in heap specia...
1 votes
1 votes
1 answer
4
tripathiambuj asked Jun 22, 2016
1,477 views
How many minimum queues are required to implement a priority queue?