内容纲要
 public static void BubbleSort(int[] arrInt) 
        {
            for (int i = 1; i < arrInt.Length; i++) 
            {
                for (int y = 0; y < arrInt.Length - i; y++) 
                {
                    if (arrInt[y] > arrInt[y + 1]) 
                    {
                        int temp = arrInt[y + 1];
                        arrInt[y + 1] = arrInt[y];
                        arrInt[y] = temp;
                    }
                }
            }
        }
 public static void SelectionSort(int[] arrInt) 
        {
            for (int i = 0; i < arrInt.Length - 1; i++) 
            {
                int index = i;
                for (int y = i+1; y < arrInt.Length; y++) 
                {
                    if (arrInt[y] < arrInt[index]) 
                    {
                        index = y;
                    }
                }
                int temp = arrInt[i];
                arrInt[i] = arrInt[index];
                arrInt[index] = temp;
            }
        }

1 对 “冒泡排序/选择排序”的想法;

发表评论