因为 STL::map
是有序映射,插入排序数据集会更快吗?特别是如果我们考虑大型数据集?
最佳答案
当然,已经对数据进行排序。
#include <map>
#include <vector>
int main() {
std::vector<int> data { 0, 1, 2, 3, 4, 5 };
std::map<int, int> result;
// From: http://en.cppreference.com/w/cpp/container/map/insert
// Amortized constant if the insertion happens in the position just before
// the hint, logarithmic in the size of the container otherwise.
for(auto i : data)
result.insert(result.end(), { i, i} );
}
关于c++ - 有序插入到 STL::map 更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39751518/