在STL列表中交换两个节点的任何快速方法? [英] Any fast method to swap two nodes in a STL list?
问题描述
要切换到列表中的节点,更改指针就足够了。但stl swap
方法似乎复制了它们的值,不是吗?
To swap to nodes in list, changing pointers is enough. But the stl swap
method seems to copy their values, doesn''t it?
推荐答案
Atlas <马***** @ gmail.com>在消息中写道
news:11 ********************* @ f14g2000cwb.googlegro ups.com ...
"Atlas" <Ma*****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
要交换到列表中的节点,更改指针就足够了。但是stl swap
方法似乎复制了它们的值,不是吗?
To swap to nodes in list, changing pointers is enough. But the stl swap
method seems to copy their values, doesn''t it?
所有标准库容器都有复制语义。
为什么这是一个问题?
-Mike
All standard library containers have copy semantics.
Why is this a problem?
-Mike
Atlas写道:
To交换到列表中的节点,更改指针就足够了。但stl swap
方法似乎复制了它们的值,不是吗?
To swap to nodes in list, changing pointers is enough. But the stl swap
method seems to copy their values, doesn''t it?
std :: list有几个叫做''splice''的方法它可以移动
列表中的节点而无需复制。
john
std::list have several methods called ''splice'' which can move nodes in a
list without copying.
john
John Harrison写道:
John Harrison wrote:
Atlas写道:
要交换到列表中的节点,更改指针就足够了。但stl swap
方法似乎复制了它们的值,不是吗?
To swap to nodes in list, changing pointers is enough. But the stl swap
method seems to copy their values, doesn''t it?
std :: list有几个叫做''splice''的方法可以移动节点在没有复制的情况下列表。
std::list have several methods called ''splice'' which can move nodes in a
list without copying.
这是不允许他想做的事情。列表可能不会自行拼接()
。
Kristo
That''s not allowed for what he wants to do. A list may not splice()
with itself.
Kristo
这篇关于在STL列表中交换两个节点的任何快速方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!