k***e 发帖数: 556 | 1 今天想实现前两天大家讨论的minmaxheap找median,结果碰到一个问题。
I want pass function pointer to create a heap that has comparison function
as I defined. Thus I don't need both minHeap maxHeap. By the way, because I
have heap with template parameters, I also need function pointers with
template parameter.
It looks like:
template
class Heap {
private:
T* data;
public:
Heap(const vector& dataSrc, bool (*cmp)(T, T);
};
However, I cannot get a function pointer with template parameter. I really
had no idea h |
H*M 发帖数: 1268 | 2 你这是好学还是什么?
如果你不想自己写的话,STL里有现成的priority_queue,稍微重写个compare的functo
r就可以用成minHeap和maxHeap了
I
【在 k***e 的大作中提到】 : 今天想实现前两天大家讨论的minmaxheap找median,结果碰到一个问题。 : I want pass function pointer to create a heap that has comparison function : as I defined. Thus I don't need both minHeap maxHeap. By the way, because I : have heap with template parameters, I also need function pointers with : template parameter. : It looks like: : template : class Heap { : private: : T* data;
|
k***e 发帖数: 556 | 3 晕 我只是自己练练手 怎么弄的像干了啥见不得人的事情一样 |
m********0 发帖数: 2717 | |
H*M 发帖数: 1268 | 5 faint to death!
【在 k***e 的大作中提到】 : 晕 我只是自己练练手 怎么弄的像干了啥见不得人的事情一样
|
H*M 发帖数: 1268 | 6 did I BS ?
【在 m********0 的大作中提到】 : lol~ : 好学都被鄙视了。
|
g*******y 发帖数: 1930 | 7 change function pointer to a functor should be ok
template class CMP{
public:
operator()(const T &t1, const T &t2){ return t1
};
template class Heap{
public:
Heap(const vector &data, CMP cmp);
};
I
【在 k***e 的大作中提到】 : 今天想实现前两天大家讨论的minmaxheap找median,结果碰到一个问题。 : I want pass function pointer to create a heap that has comparison function : as I defined. Thus I don't need both minHeap maxHeap. By the way, because I : have heap with template parameters, I also need function pointers with : template parameter. : It looks like: : template : class Heap { : private: : T* data;
|