Shifting/aligning/rotating a circular buffer to zero in-place

前端 未结 5 1656
谎友^
谎友^ 2021-02-02 00:13

I\'m using a circular buffer to push data onto either end of a list. After I\'m done I want to align the buffer so the first element in the list is at position zero and can be u

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 00:50

    First of all you should not align the buffer. Looks like an unnecessary overhead.

    The tastes way to implement this should be

    1) Create a new array
    2) Copy elements (std::copy) from n=0 to end of array
    3) Copy begining of the array from f=0 to n=6
    4) std::swap arrays

提交回复
热议问题