【发布时间】:2020-07-06 13:13:44
【问题描述】:
从here,我能够将元组向量转换为堆。 但是我想更进一步地从头开始构造元组,从而消除了转换向量的需要。
我之前构造向量的方式如下:
vector<tuple<int,int,int>> x;
for (int ii=0; ii < 10; ii++){
for (int jj=0; jj < 10; jj++){
y[0] = ii + rand() % 10;
y[1] = jj + rand() % 10;
y[2] = rand() % 100;
x.emplace_back(y[0], y[1], y[2]);
}
}
我是如何尝试的,从头开始构建一个堆
struct Comp {
bool operator()(const tuple<int,int,int>& a,
const tuple<int,int,int>& b){
return (get<2>(a) < get<2>(b));
}
};
vector<tuple<int,int,int>> x;
for (int ii=0; ii < 10; ii++){
for (int jj=0; jj < 10; jj++){
y[0] = ii + rand() % 10;
y[1] = jj + rand() % 10;
y[2] = rand() % 100;
x.emplace_back(y[0], y[1], y[2]);
push_heap(x.begin(), x.end(), Comp()); // using push_heap
}
}
push_heap() 行上的错误:
Severity Code Description Project File Line Suppression State
Error C2228 left of '.begin' must have class/struct/union
Error (active) E0153 expression must have class type
Error (active) E0153 expression must have class type
Error C2780 'void std::push_heap(_RanIt,_RanIt,_Pr)': expects 3 arguments - 2 provided
Error C2672 'push_heap': no matching overloaded function found
【问题讨论】:
-
请在问题中包含minimal reproducible example