数组中的元素右移5

我想通过仅更改索引将一个数组中的元素向右移动。另外,我不想使用内置功能

例如,如果我们有

  

8,6,5,3,9

那么我们将拥有

  

9,8,3

如果数组没有足够的长度。其余的元素移位将从数组的第一个索引开始。

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:backgroundTint="#000"
/> 

这是我尝试过的,但是不起作用

yxj7078 回答:数组中的元素右移5

如果移位计数小于或等于数组大小,则可以使用以下代码(我由this link编辑了答案):

        using System;

        int M = 5;//shift count
        int size; //size of array
        int[] myarray = new int[int.Parse(Console.ReadLine())];
        for (int i = 0; i < myarray.Length; i++)
        {
            myarray[i] = int.Parse(Console.ReadLine());
        }

        size = myarray.Length;
        if (size >= M)
        {
            Array.Reverse(myarray,size);
            Array.Reverse(myarray,M);
            Array.Reverse(myarray,M,size - M);

            for (int i = 0; i < myarray.Length; i++)
            {
                Console.Write(myarray[i]+"\t");
            }

            Console.Read();
         }
本文链接:https://www.f2er.com/3146326.html

大家都在问