C # how to realize the left and right rotation of array elements
This article mainly introduces how to realize the left and right rotation of array elements in c #. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
We define an array of elements, for example: 1 2 3 4 5 6
Right-handed: 2 3 4 5 6 1
Left-handed: 6 1 2 3 4 5
If we rotate one bit to the right, we will think of turning the array element as a whole, putting the first element in the last bit, and then moving each bit to the left. We can first take out the first element and mark it tmp=arr [0], then each move forward one bit, ARR [I -] = ARR [I], and finally put tmp in the last place.
By the same token, the principle of right-handed n bit is the same as right-handed one bit, except that each rotation in a cycle, NMurray, until zero.
Code:
# include void RVast (int arr [], int len,int n) {int i; int tmp; while (n) {tmp=arr [0]; for