For Stack: just make a structure:
struct stack_with_priorityqueue { int num; int priority; struct stack_with_priorityqueue *ptr; } now when we add another number just increase the priority... priority++.... For Queue: do same...just decrease priority...priority--.... ... On Wed, Sep 14, 2011 at 4:41 PM, bharatkumar bagana < bagana.bharatku...@gmail.com> wrote: > The well known examples of priority queue is minheap and maxheap.. > i guess the question is how do we implement one of these(at least) using > queue? > > > On Wed, Sep 14, 2011 at 9:08 AM, Ankuj Gupta <ankuj2...@gmail.com> wrote: > >> I guess the functionality of priority should be maintained >> >> On Sep 13, 11:59 pm, Ankur Garg <ankurga...@gmail.com> wrote: >> > But dude are u saying stack will be implemented as a map with >> > <value,priority> >> > >> > and then choose element based on priority ? >> > >> > regards >> > Ankur >> > >> > >> > >> > >> > >> > >> > >> > On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta <ankuj2...@gmail.com> >> wrote: >> > >> > > For stack :- Keep incrementing the priority of each pushed element. So >> > > the last pushed element will have the greatest priority and the >> > > element pushed first will have >> > > lowest priority. >> > > For queue:- keep decrementing the priority of each inserted element. >> > >> > > On Sep 13, 1:45 am, Ankur Garg <ankurga...@gmail.com> wrote: >> > > > How to Implement a Queue with a Priority Queue >> > > > Similarly how woud you implement Stack with Priority Queue >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "Algorithm Geeks" group. >> > > To post to this group, send email to algogeeks@googlegroups.com. >> > > To unsubscribe from this group, send email to >> > > algogeeks+unsubscr...@googlegroups.com. >> > > For more options, visit this group at >> > >http://groups.google.com/group/algogeeks?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > > **Please do not print this e-mail until urgent requirement. Go Green!! > Save Papers <=> Save Trees > *BharatKumar Bagana* > **http://www.google.com/profiles/bagana.bharatkumar<http://www.google.com/profiles/bagana.bharatkumar> > * > Mobile +91 8056127652* > <bagana.bharatku...@gmail.com> > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.