Added method "sort(bool)" to sort the element of the queue in ascending or descending order
This commit is contained in:
parent
65336cfe7b
commit
0491ceedeb
|
@ -21,21 +21,45 @@
|
|||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _PriorityQueue_h_
|
||||
#define _PriorityQueue_h_
|
||||
#ifndef _PRIORITYQUEUE_H_
|
||||
#define _PRIORITYQUEUE_H_
|
||||
|
||||
/** Implements a bounded-size max priority queue using a heap
|
||||
*/
|
||||
template <typename Index, typename Weight>
|
||||
class HeapMaxPriorityQueue
|
||||
{
|
||||
#include <algorithm>
|
||||
|
||||
namespace vcg {
|
||||
|
||||
/** Implements a bounded-size max priority queue using a heap
|
||||
*/
|
||||
template <typename Index, typename Weight>
|
||||
class HeapMaxPriorityQueue
|
||||
{
|
||||
struct Element
|
||||
{
|
||||
Weight weight;
|
||||
Index index;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
struct
|
||||
{
|
||||
bool operator()(const Element& a, const Element& b) const
|
||||
{
|
||||
return a.weight < b.weight;
|
||||
}
|
||||
} lessElement;
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
bool operator()(const Element& a, const Element& b) const
|
||||
{
|
||||
return a.weight > b.weight;
|
||||
}
|
||||
} greaterElement;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
HeapMaxPriorityQueue(void)
|
||||
{
|
||||
|
@ -118,12 +142,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void sort(bool ascending = true)
|
||||
{
|
||||
if (ascending)
|
||||
std::sort(mElements, mElements + mCount, lessElement);
|
||||
else
|
||||
std::sort(mElements, mElements + mCount, greaterElement);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
int mCount;
|
||||
int mMaxSize;
|
||||
Element* mElements;
|
||||
Element* mpOffsetedElements;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue