列表< T>替代... [英] list<T> alternative...
问题描述
我正在编写一个实时应用程序,目前正在使用C ++链接
列表。物品必须分类。我收集物品时,
按顺序搜索列表,直到找到插入点,然后插入
项目。
这被证明效率低下。是否有更有效的替代方案
(可能在Boost或标准C中)?
I''m writing a real-time application which is currently using C++ linked
lists. The items have to be sorted. I collect the items as they come in,
search the list sequentially until I find the insertion point, and insert
the item.
This is proving to be inefficient. Is there a more efficient alternative
(maybe in Boost or standard C)?
推荐答案
barcaroller写道:
barcaroller wrote:
我正在编写一个实时应用程序,目前正在使用C ++链接
列表。物品必须分类。我收集物品时,
按顺序搜索列表,直到找到插入点,然后插入
项目。
这被证明效率低下。是否有一个更有效的替代方案
(可能在Boost或标准C中)?
I''m writing a real-time application which is currently using C++ linked
lists. The items have to be sorted. I collect the items as they come in,
search the list sequentially until I find the insertion point, and insert
the item.
This is proving to be inefficient. Is there a more efficient alternative
(maybe in Boost or standard C)?
看看std :: lower_bound,使用二进制搜索。应该是比顺序搜索快得多的b $ b。
-
Scott McPhillips [VC ++ MVP]
Have a look at std::lower_bound, which uses a binary search. Should be
much faster than a sequential search.
--
Scott McPhillips [VC++ MVP]
barcaroller写道:
barcaroller wrote:
我正在编写一个当前正在使用C ++链接的实时应用程序
列出。物品必须分类。我收集物品时,
按顺序搜索列表,直到找到插入点,然后插入
项目。
这被证明效率低下。是否有一个更有效的替代方案
(可能在Boost或标准C中)?
I''m writing a real-time application which is currently using C++ linked
lists. The items have to be sorted. I collect the items as they come in,
search the list sequentially until I find the insertion point, and insert
the item.
This is proving to be inefficient. Is there a more efficient alternative
(maybe in Boost or standard C)?
你看过std吗? :: set< ??
HTH!
Have you taken a look at std::set<??
HTH!
" Scott McPhillips [MVP]" < org-dot-mvps-at-scottmcpwrote in message
news:Xo ************************** ****@comcast.com。 ..
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcpwrote in message
news:Xo******************************@comcast.com. ..
barcaroller写道:
barcaroller wrote:
>我正在编写一个实时应用程序目前正在使用C ++链接的列表。物品必须分类。我收集物品时,按顺序搜索列表,直到找到插入点,然后插入物品。
这证明效率低下。是否有更有效的替代方案
(可能在Boost或标准C中)?
>I''m writing a real-time application which is currently using C++ linked
lists. The items have to be sorted. I collect the items as they come
in, search the list sequentially until I find the insertion point, and
insert the item.
This is proving to be inefficient. Is there a more efficient alternative
(maybe in Boost or standard C)?
看看std :: lower_bound,它使用二进制搜索。应该比顺序搜索快得多b $ b。
Have a look at std::lower_bound, which uses a binary search. Should be
much faster than a sequential search.
如果容器是一个列表,则无济于事,因为在给定双向迭代器的情况下,lower_bound
退化为顺序搜索。
PJ Plauger
Dinkumware,Ltd。
http://www.dinkumware.com
这篇关于列表< T>替代...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!