PicO wrote:

i need some explanation about the difference between priority queue &

set & heap ... as they all sort the data in ( n log n ) ... but the

only i see that priority queue only can pop the top ( maximum

element ) while set and heap can erase any element ...

The advantage of a priority queue (in cases where you just need the

smallest item in a group of values) over a set is that the priority

queue will take much less memory. A priority queue can be constructed

into a vector (ie. a contiguous array) and thus it will only require

as much memory as the sizes of the elements. A set will take much more

memory (because besides the elements themselves it needs 3 pointers

per element, plus the additional overhead caused by allocating each

element dynamically).