Priority queue using heap

can anyone give me an algorithm or any idea of making priority queue using heap.
there are 2 ways to do these.
1 -- have a vector or other container of normal queues and load them by priority and read from them by priority. vectors go on the heap for you.
2-- you can have a sortable container and your data contains the priority field, so you can sort by it, but you have to use a slower (more complex) stable-sort. whatever container should also use the heap if that is a requirement. a 'cheaper' way to do a stable sort is to have a bogus counter value in your data, the first entry is 0, the second is 1 … the nth is n-1 … and so on. Sort by priority first and counter second (one sort operation, using 2 datas to compare for ordering).
Last edited on
Topic archived. No new replies allowed.