国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

委托的一個應用---冒泡

2019-11-17 02:51:18
字體:
來源:轉載
供稿:網友

委托的一個應用---冒泡

參考《C#高級編程》

直接上代碼,代碼比較簡單

 1     class PRogram 2     { 3         private delegate string GetAString(); 4         static void Main(string[] args) 5         { 6              7             int[] a = { 0, 5, 6, 2, 1 }; 8             BubbleSorter.Sort(a, BubbleSorter.Compa); 9             foreach (var item in a)10             {11                 Console.Write(item);12             }13             Console.ReadLine();14         }15 16         public static void SortA(int[] sortArray)17         {18             bool swapped = true;19             do20             {21                 swapped = false;22                 for (int i = 0; i < sortArray.Length - 1; i++)23                 {24                     if (sortArray[i] < sortArray[i + 1])25                     {26                         int temp = sortArray[i];27                         sortArray[i] = sortArray[i + 1];28                         sortArray[i + 1] = temp;29                         swapped = true;30                     }31                 }32             }33             while (swapped);34         }35     }36 37     class BubbleSorter38     {39         static public void Sort<T>(IList<T> sortArray, Func<T, T, bool> comparison)40         {41             bool swapped = true;42             do43             {44                 swapped = false;45                 for (int i = 0; i < sortArray.Count - 1; i++)46                 {47                     if (comparison(sortArray[i + 1], sortArray[i]))48                     {49                         T temp = sortArray[i];50                         sortArray[i] = sortArray[i + 1];51                         sortArray[i + 1] = temp;52                         swapped = true;53                     }54                 }55             } while (swapped);56         }57 58         public static bool Compa(int i, int j)59         {60             return i < j;61         }62     }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宽城| 曲阳县| 兖州市| 广安市| 贵溪市| 遂川县| 隆德县| 浦东新区| 峨眉山市| 峨眉山市| 信丰县| 江孜县| 建昌县| 武功县| 临泽县| 个旧市| 青海省| 调兵山市| 嘉义县| 营口市| 城固县| 繁昌县| 民乐县| 开化县| 彭山县| 和田县| 文山县| 蓬安县| 武定县| 确山县| 长沙县| 孟州市| 广宁县| 松滋市| 沅江市| 太谷县| 灌南县| 安阳县| 社会| 大化| 宜兰县|