我已经分配了vector<vector<long>>
.在不重定位数据的情况下创建直方图或使用 std::find 遍历所有 vector 的正确方法是什么?
谢谢
最佳答案
通过直方图,我理解 map 值->出现次数,对于您的数据,这意味着 map<int, int>
而且我不明白 std::find 是如何开始的。说这个我会去做这样的事情:
// assuming exists vector<vector<long<long>>
std::map<long, int> histogram ;
for (const auto &v1 : vect)
for (auto value : v1)
{
auto it = histogram.find(value) ;
if (it == histogram.end())
histogram[value] = 1 ;
else
it->second++ ;
}
关于c++ - 我怎样才能创建 vector 的直方图<vector<long>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30993289/