本文实例讲述了C#选择法排序实现方法。分享给大家供大家参考。具体实现方法如下:
public int[] SelectionSort(int[] arr){ //1. Find min //2. Swap it with first element //3. Repeat starting from secong position onwards. int _min = 0; for (int i = 0; i < arr.Length; i++) { _min = i; for (int j = i; j < arr.Length; j++) { if (arr[j] < arr[_min]) _min = j; } int _temp = arr[i]; arr[i] = arr[_min]; arr[_min] = _temp; } return arr;}
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答