【问题标题】:Distance between multiset iterator多集迭代器之间的距离
【发布时间】:2013-04-05 02:55:02
【问题描述】:

我们能否找到复杂度小于 O(n) 的多重集中的两个迭代器之间的距离?
我尝试使用迭代器标头提供的 std::distance() 函数。但它的内部实现对于多集迭代器是 O(n)。

【问题讨论】:

  • 不,O(n) 在这种情况下是你能做的最好的。

标签: c++ stl iterator multiset


【解决方案1】:

multiset::iterator 模型 BidirectionalIterator,而不是 RandomAccessIterator,所以 std::distance 只需要是线性的,而不是常量。

【讨论】:

    猜你喜欢
    • 2019-02-23
    • 2012-09-13
    • 1970-01-01
    • 2017-08-03
    • 2020-04-27
    • 2019-01-14
    • 2014-05-24
    • 2020-05-29
    • 2020-09-03
    相关资源
    最近更新 更多