Element at index in a std::set?

前端 未结 6 452
太阳男子
太阳男子 2020-12-03 00:46

I\'ve stumbled upon this problem: I can\'t seem to select the item at the index\' position in a normal std::set. Is this a bug in STD?

Below a simple ex

6条回答
  •  悲哀的现实
    2020-12-03 01:40

    There is no way you can access it in constant time.

    But you can reach to any element in O(n) time. E.g.

    std::set::iterator it;
    it=my_set.begin();
    advance(it,n);
    cout<<*it;
    

提交回复
热议问题