• edited by
1,283 views

1 Answer

0 0 votes
I think you are asking for implementation of stack with the help of priority queue.

Stack is First in Last Out.

So to make priority queue working as a stack , we need priority with the element.

The First element have to be lowest priority , because it will popped out at last from the data structure,

And the last element should have highest priority becayse it have to popped out first.

So Lets take first element have priority 1 , second element 2  and so on.....

This will make our priority queue work as stack.

As priority queue  required log(N) cost in case of Enqueue( push opeation ) and Dequeue( pop operation )

Further complexity of push operation can be reduced to constant, as in case of Fibonacci heap data structure , if our priority heap was implemented by Fibonacci heap , then Enqueu in O(1) and Dequeu in Log(N).
Position:
Show:

Related questions

0 0 votes
1 1 answer
1.7k
1.7k views
pallaviamu asked Jun 17, 2018
1,722 views
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 o...
0 0 votes
0 0 answers
1.0k
1.0k views
srestha asked Dec 22, 2018
1,010 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 1 vote
1 1 answer
2.2k
2.2k views
tripathiambuj asked Jun 22, 2016
2,246 views
How many minimum queues are required to implement a priority queue?
8 8 votes
2 2 answers
603
603 views
GO Classes asked Jul 27
603 views
Which of the following statements are true?$\text{S1.}$ Stack operations $\texttt{push}$, $\texttt{pop}$, and $\texttt{isEmpty}$ can be worst-case $O(1)$ for a linked-lis...