本文介绍了快速STL数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, 我想使用C ++ STL来存储一组对象',其次是 如下: class Object { public: int value; .. .... } 我需要执行以下操作: 1.将对象排序他们的价值的增加顺序。 2.排序后,我需要随机访问一些对象。 据我所知,矢量随机访问非常有效。然而,排序大小为n的向量需要O(nlog n)时间,这是不好的。 是否有良好的数据结构(或者是某些)这样它可以随机访问和排序吗? 谢谢。Hello,I would like to use C++ STL to store a set of Object''s which is asfollows:class Object{public:int value;......}I need to perform the following actions:1. Sort Objects in the increasing order of their "value".2. After sorting, I need to randomly access some of the Objects.As I know, vector is very efficient in random access. However, sortingvector of size n takes O(nlog n) time which is not good.Is there a good data structure (or a combination of some) such that itis efficient in random access and sorting?Thank You.推荐答案 将它们收集在一个集合中,然后将该集合复制到一个向量中。 V - 请在通过电子邮件回复时删除资金''A' 我没有回复最热门的回复,请不要问Collect them in a set, then copy the set into a vector.V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask 将它们收集在一个集合中,然后将该集合复制到一个向量中。 V - 请在通过电子邮件回复时删除资金''A' 我没有回复最热门的回复,请不要问Collect them in a set, then copy the set into a vector.V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask 这篇关于快速STL数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!