首页 > 代码库 > C# 排序算法

C# 排序算法

    class Sort    {        static void swap<T>(ref T a, ref T b)        {            T tmp = a;            a = b;            b = tmp;        }        #region 冒泡排序        public static void Sort1(ref int[] arr)        {            for (int i = 0; i < arr.Length - 1; i++)                for (int j = i + 1; j < arr.Length; j++)                    if (arr[i] > arr[j])                        swap(ref arr[i], ref arr[j]);        }        public static void Sort1(ref float[] arr)        {            for (int i = 0; i < arr.Length - 1; i++)                for (int j = i + 1; j < arr.Length; j++)                    if (arr[i] > arr[j])                        swap(ref arr[i], ref arr[j]);        }        public static void Sort1(ref double[] arr)        {            for (int i = 0; i < arr.Length - 1; i++)                for (int j = i + 1; j < arr.Length; j++)                    if (arr[i] > arr[j])                        swap(ref arr[i], ref arr[j]);        }        public static void Sort1(ref string[] arr)        {            for (int i = 0; i < arr.Length - 1; i++)                for (int j = i + 1; j < arr.Length; j++)                    if (arr[i].CompareTo(arr[j]) > 0)                        swap(ref arr[i], ref arr[j]);        }        #endregion    }

 

C# 排序算法