Hello all,
I have some stupid questions, but it would be great if some one helps.
we know priority_queue of STL right ??
priority_queue<T, Sequence, Compare>
so i can declare it like this.. priority_queue< node, vector < node >, compare > Q ;
and suppose i have a vector.. vector < node > V ;
is there any way i could make priotiy_queue use my vector V as it's sequence ..?
I mean there would be a priority_queue which have a sequence of vector < node > type and i'll modify the vector V, and pop up the desired result from Q.
so basically...
Wouldn't it be better then for V to be a priority queue? If you need to access the middle elements, you can always just do (&V.top())[i]
Thanx :D, i c ur point, but still could u clearify a bit with a code sample ?? (I mean i have confusion i will make V a priority queue, then all the same each time i have to sort with a function or u say i just keep a normal vector and keep popping up from anywhere meanwhile keeping other mechanism for detecting which element comes next ?? But thank u though, ur idea is innovative.
Well, a priority queue is just a regular container, such as a vector, which is sorted based on a certain criterion each time a new item is added. So, if a vector is used internally to store the elements, that means that particular priority queue has all the properties of a vector, such as adjacency of elements:
1 2 3 4 5
std::vector<int> v;
v.push_back(1);
v.push_back(2);
int *p=&(v.front());
std::cout <<p[0]<<' '<<p[1];
Therefore, if you get a pointer to the top element, you can find the other elements using the offset operator: