"Rich S." wrote:[color=blue]
>
> I tried it and it worked but the only down side is that when I go to dump
> the 2000 they're are in ascending order and I wish them to be in descending
> order. There must be a way to dump the p queue into a vector quickly[/color]
A loop ?
std::vector<T> Result;
Result.reserve( N );
while( !q.empty() )
Result.push_back( q.top() );
q.pop();
}
[color=blue]
> and
> sort that[/color]
No need to sort it.
The items poped from the queue already are sorted. Just iterate
through the vector in reverse order.
[color=blue]
> and then dump it.
>[/color]
If you don't want to create that vector, you could eg. use
a recursive function to flip the order:
void Dump( priority_queue< T, std::vector<int>, MyLess<int> > q )
{
if( q.empty() )
return;
T Value = q.top();
q.pop();
Dump( q );
cout << Value << endl;
}
but I doubt, that this is faster, clearer or uses less memory space then
the vector.
--
Karl Heinz Buchegger
kbuchegg@gascad.at