什么时候std :: list比其他容器更有效? [英] When is std::list more effective than the other containers?

查看:115
本文介绍了什么时候std :: list比其他容器更有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是出于好奇:


什么时候使用std :: list比使用

其他容器(例如vector,deque)更有效/更有效等等?


据我所知,列表似乎并不专门用于

任何东西。

谢谢,

Josh McFarlane

Just out of curiosity:

When would using std::list be more efficient / effective than using
other containers such as vector, deque, etc?

As far as I''m aware, list doesn''t appear to be specialized for
anything.

Thanks,
Josh McFarlane

推荐答案



Josh Mcfarlane写道:
Hi

Josh Mcfarlane wrote:
出于好奇:

什么时候使用std :: list比使用其他容器如vector,deque等?

据我所知,列表似乎并不适用于
任何东西。
Just out of curiosity:

When would using std::list be more efficient / effective than using
other containers such as vector, deque, etc?

As far as I''m aware, list doesn''t appear to be specialized for
anything.




想想在任意

位置擦除或插入元素的复杂性。还要考虑迭代器在这样做时会发生什么。

Markus



Think about the complexity of erasing or inserting elements at arbitrary
positions. Also think about what happens to iterators when doing so.

Markus




Markus Moll写道:

Markus Moll wrote:


Josh Mcfarlane写道:
Hi

Josh Mcfarlane wrote:
出于好奇:
什么时候使用std :: list比使用
其他容器如vector,deque等更有效/更有效?

据我所知,列表没有''似乎是专门用于任何事情。
Just out of curiosity:

When would using std::list be more efficient / effective than using
other containers such as vector, deque, etc?

As far as I''m aware, list doesn''t appear to be specialized for
anything.


想想在任意位置擦除或插入元素的复杂性。还要考虑迭代器在执行此操作时会发生什么。



Think about the complexity of erasing or inserting elements at arbitrary
positions. Also think about what happens to iterators when doing so.




拼接子向量也相当棘手;)


HTH,

Michiel Salters



Splicing subvectors is also rather tricky ;)

HTH,
Michiel Salters




删除和插入操作列表的运行时间优于矢量。


当你从vector中删除任何东西时,必须重新分配该项后面的所有迭代器

。没有这样的事情。

The runtime of list for
deletion and insertion operation is better than vectors.

When you delete anything from vector, all the iterators after that item
must be reassigned. no such thing wtih list.


这篇关于什么时候std :: list比其他容器更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆