# C#常用排序算法

 ///         /// 冒泡排序         ///         /// 进行排序的整型数组         public static void BubbleSorter(int[] list)         {             int i, j, temp;             bool done = false;//判断是否已经排序过             j = 1;             while ((j < list.Length) && (!done))             {                 done = true;                 for (i = 0; i < list.Length - j;i++)                 {                     if (list[i] > list[i + 1])                     {                         done = false;                         //交换位置                         temp = list[i];                         list[i] = list[i + 1];                         list[i + 1] = temp;                     }                 }                 j++;             }         }

 ///         /// 选者最小值排序法         ///         /// 进行排序的整型数组         public static void SelectMinSorter(int[] list)         {             int min, temp;             for (int i = 0; i < list.Length; i++)             {                 min = i;                 for (int j = i + 1; j < list.Length; j++)                 {                     if (list[j] < list[min])                         min = j;                 }                 temp = list[min];                 list[min] = list[i];                 list[i] = temp;             }         }           ///         /// 选者最大值排序法         ///         /// 进行排序的整型数组         public static void SelectMaxSorter(int[] list)         {             int max, temp;             for (int i = 0; i < list.Length; i++)             {                 max = i;                 for (int j = i + 1; j < list.Length; j++)                 {                     if (list[j] > list[max])                         max = j;                 }                 temp = list[max];                 list[max] = list[i];                 list[i] = temp;             }         }

 ///         /// 插入排序         ///         /// 进行排序的整型数组         public static void InsertSorter(int[] list)         {             int j,temp;             for (int i = 1; i < list.Length; i++)             {                 j =  i;                 temp = list[i];                 while ((j > 0) && (list[j - 1] > temp))                 {                     list[j] = list[j - 1];                     --j;                 }                 list[j] = temp;             }         }

 ///         /// 希尔排序         ///         /// 进行排序的整型数组         public static void ShellSorter(int[] list)         {             int inc;             for (inc = 1; inc < list.Length / 9; inc = 3 * inc + 1) ;             for (; inc > 0; inc /= 3)             {                 for (int i = inc + 1; i <= list.Length; i += inc)                 {                     int temp = list[i - 1];                     int j = i;                     while ((j > inc) && (list[j - inc - 1] > temp))                     {                         list[j - 1] = list[j - inc - 1];                         j -= inc;                     }                     list[j - 1] = temp;                 }             }         }

• 本文已收录于以下专栏：

举报原因： 您举报文章：C#常用排序算法 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)