由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问大家一个cpp中function pointer的问题
相关主题
An interview question of finding the median in a moving window.Top K in N sorted array
Two-Sigma面经问一道题(9)
问个题G家电面的两个题
G家电面题目sliding windows中维持topk频繁的query
问两道google题LinkedIn面经(已跪),攒个rp
讨论一道题刚电面完l家,只敲了一道题,看来是挂了。。。
发个一直没有见过满意答案的题吧面试用C++, heap 怎么办?
问个design的问题C++ Q90 - Q92
相关话题的讨论汇总
话题: heap话题: function话题: template话题: pointer话题: cmp
进入JobHunting版参与讨论
1 (共1页)
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
4
lol~
好学都被鄙视了。
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;

1 (共1页)
进入JobHunting版参与讨论
相关主题
C++ Q90 - Q92问两道google题
攒人品,twitter电话面经讨论一道题
又想起一道google题目发个一直没有见过满意答案的题吧
请教MinHeap用STL实现问个design的问题
An interview question of finding the median in a moving window.Top K in N sorted array
Two-Sigma面经问一道题(9)
问个题G家电面的两个题
G家电面题目sliding windows中维持topk频繁的query
相关话题的讨论汇总
话题: heap话题: function话题: template话题: pointer话题: cmp