Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 改进的选择排序越界错误_C#_Arrays_Sorting - Fatal编程技术网

C# 改进的选择排序越界错误

C# 改进的选择排序越界错误,c#,arrays,sorting,C#,Arrays,Sorting,我有一个方法是“选择排序的改进版本”。但是,代码不是以“temp[x]=0”的形式运行的;此行给出了数组错误的界限。我不想使用ArrayList。如何将此行更改为数组的边界 public static void ImprovedSelectionSort(int[] Array) { Stopwatch timer = new Stopwatch(); timer.Start(); int[] temp = new int[Arra

我有一个方法是“选择排序的改进版本”。但是,代码不是以“temp[x]=0”的形式运行的;此行给出了数组错误的界限。我不想使用ArrayList。如何将此行更改为数组的边界

    public static void ImprovedSelectionSort(int[] Array)
    {
        Stopwatch timer = new Stopwatch();
        timer.Start();
        int[] temp = new int[Array.Length];
        for (int x = 1; x <= Array.Length; x++)
        {
            //OtherList.Add(0); -- what I want to do
            temp[x] = 0;
        }

        int n = Array.Length;
        int i = 0;
        while (i < n)
        {
            int rear = 0; 
            int curMax = Array[i]; 
           temp[rear] = i; 
            int j = i + 1;

            while (j < n)
            {
                if (curMax < Array[j])
                {
                    curMax = Array[j];
                    rear = -1;
                }
                if (curMax == Array[j])
                {
                    rear = rear + 1;
                    temp[rear] = j;
                }
                j++;
            }
            int front = 0;
            int p = Array[temp[front]];
            while (front <= rear)
            {
                int temporary = p;
                Array[temp[front]] = Array[i];
                Array[i] = temporary;
                i++;
                front += 1;
            }
        }
publicstaticvoid-ImprovedSelectionSort(int[]数组)
{
秒表计时器=新秒表();
timer.Start();
int[]temp=newint[Array.Length];
对于(int x=1;x
对于(intx=1;x更改(intx=1;x)的