Optimal way to perform a shift operation on an array

前端 未结 6 1502
醉酒成梦
醉酒成梦 2021-02-20 08:00

Suppose I have an array

unsigned char arr[]= {0,1,2,3,4,5,6,7,8,9};

Is there a way to perform shift operation on them besides just copying them

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 08:42

    If you want a circular shift of the elements:

    std::rotate(&arr[0], &arr[1], &arr[10]);
    

    ... will do the trick. You'll need to #include the algorithm header.

提交回复
热议问题