C#向右移动数组

编程入门 行业动态 更新时间:2024-10-26 20:31:01
本文介绍了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#向右移动数组

本文发布于:2023-11-06 17:17:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!