Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report