C # Select Sort
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace sort {Class Selectsorter {public static int[] Sort (int[] a) {Select Sort (a); return A; } private static void Selectsort (int[] myArray) {int I, j, smallest; Data starting position, from 0 to penultimate data for (i = 0; i < myarray.length-1; i++) {smallest = i;// Minimum data is recorded for (j = i + 1; j < Myarray.length; J + +) {//In the remaining data to find the most Small data if (Myarray[j] < myarray[smallest]) {smallest = j;//as The result is smaller than it, record subscript}}//To swap the smallest data and unsorted First Data swap (ref Myarray[i], Ref myarray[smallest]); }} private static void Swap (ref int left, ref int. right) {int Temp temp = left; left = right; right = temp; } } }
Choose the idea of sorting:
Example:
The above is the C # selection sort of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!