本文介绍了C#向右移动数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个问题,我确实成功地向左移动,但是我向右移动时遇到了问题这就是我向左移动的方式:
so I have a problem I did shifting to left successfully but I have problems with shifting to right This is how I shift to the left:
示例我的意思是左右移动:
Example what I mean shift to left and right:
- 您有一个数组:1,2,3,4,5,
- 向左移动一,2、3、4、5、1
- 向右移动一:5、1、2、3、4,
向右移动非常相似,因此向左移动,您只需要保存 last 元素而不是 first 元素,然后从末尾开始依次迭代:
Shifting to the right is quite similar so shifting to the left, you just need to save the last element instead of the first one, and iterate from the end backwards:
int t = tab[tab.Length - 1]; for (int i = tab.Length - 1; i > 0; i--) tab[i] = tab[i - 1]; tab[0] = t;更多推荐
C#向右移动数组
发布评论