Get the App
SLTechnology News&Howtos  ›  Development  › 

C # how to realize the left and right rotation of array elements

Shulou Source: shulou.com Published: 2022-06-02 02:19:00 10月03日 Update

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

Tags: Elements arrays left-handed mobile caching code content principles addresses totals tags articles different same value interests guys buddies that is more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux OPPO Reno Apple MySQL