快速STL数据结构 [英] Fast STL data structure
问题描述
您好,
我想使用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 as
follows:
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, sorting
vector 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 it
is efficient in random access and sorting?
Thank You.
推荐答案
ti******@gmail.com 写道:
我想使用C ++ STL来存储一组Object,其中包含:
如下:
>
class Object
{
public:
int value;
..... 。
}
我需要执行以下操作:
1.按升序排序对象他们的价值。
2.排序后,我需要随机访问一些对象。
据我所知,矢量非常有效随机访问。然而,排序大小为n的
向量需要O(nlog n)时间,这是不好的。
是否有良好的数据结构(或者是某些)这样它可以在随机访问和排序中有效吗?
I would like to use C++ STL to store a set of Object''s which is as
follows:
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, sorting
vector 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 it
is efficient in random access and sorting?
将它们收集在一个集合中,然后将该集合复制到一个向量中。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要问
Collect them in a set, then copy the set into a vector.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
它们的排序优于O(n lg n),但它们是通用的,
因此不容易模板化。尝试实现基数/计数排序
存储在向量中的数据。
tim.l ... @ gmail.com写道:
their are sorts that are better than O(n lg n), but they are general,
and hence not easily templatized. try implementing radix/counting sort
for your own data stored within a vector.
tim.l...@gmail.com wrote:
你好,
我想使用C ++ STL来存储一组Object',这就是
如下:
class Object
{
public:
int value;
......
}
我需要执行以下操作:
1.按照值的递增顺序对对象进行排序。
2.排序后,我需要随机访问一些对象。
据我所知,vector在随机访问方面非常有效。然而,排序大小为n的
向量需要O(nlog n)时间,这是不好的。
是否有良好的数据结构(或者是某些)这样它可以随机访问和排序吗?
谢谢。
Hello,
I would like to use C++ STL to store a set of Object''s which is as
follows:
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, sorting
vector 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 it
is efficient in random access and sorting?
Thank You.
收集一套仍然是O(n lg n)
Victor Bazarov写道:
collecting in a set is still O(n lg n)
Victor Bazarov wrote:
ti******@gmail.com 写道:
我想使用C ++ STL存储一组Object',其中包含:
$
class对象
{
public:
int value;
......
}
我需要执行以下操作:
1.按照值的递增顺序对对象进行排序。
2.排序后,我需要随机访问一些对象。
据我所知,vector在随机访问中非常有效。然而,排序大小为n的
向量需要O(nlog n)时间,这是不好的。
是否有良好的数据结构(或者是某些)这样它可以在随机访问和排序中有效吗?
I would like to use C++ STL to store a set of Object''s which is as
follows:
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, sorting
vector 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 it
is efficient in random access and sorting?
将它们收集在一个集合中,然后将该集合复制到一个向量中。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要问
Collect them in a set, then copy the set into a vector.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于快速STL数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!