Move list element to the end in STL

后端 未结 3 685
野性不改
野性不改 2020-12-06 08:58

I have already the list pointer of CDrawObject*

std::list elements;

How I can move some element to the end of list. I s

相关标签:
3条回答
  • 2020-12-06 09:46

    A std::list is a doubly-linked list, which means you do not have random access to element n. You have to can remove the element, and then use push_back.

    0 讨论(0)
  • 2020-12-06 09:48

    Use the list method splice()

    void list::splice ( iterator position, list<T,Allocator>& x, iterator i );

    Move iterator i from list x into current list at position "position"

    Thus to move it to the end put

    x.splice( x.end(), x, iter );
    

    (they can both be the same list or different lists as long as the list from which the item is moved has the same type, both T and Allocator)

    0 讨论(0)
  • 2020-12-06 09:53

    Remove it then append it to your list.

    0 讨论(0)
提交回复
热议问题