How can I shift elements inside STL container

前端 未结 2 488
你的背包
你的背包 2020-12-18 05:25

I want to shift elements inside container on any positions to the left or right. The shifting elements are not contiguous.

e.g I have a vector {1,2,3,4,5,6,7,8} and

2条回答
  •  离开以前
    2020-12-18 05:44

    Can't you do a simple insert and then erase?

    Don't forget that you'll invalidate any iterators that refer to elements above the removal or insertion point, whichever is lowest.

    HTH

    cheers,

    Rob

提交回复
热议问题