Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace selectsort{class Program {static void Main (string[] args) {int[] Arry = {1, 4, 5,6,2,9,0,8,3,10}; Selectesort (Arry, Arry. Length); for (int i = 0; i < Arry. Length; i++) Console.WriteLine (Arry[i]); Console.readkey (); }///<summary>///Select sort//idea: Get a minimum value from the array, and then place the first bit of the data. Then choose a minimum from the remaining values, and place it in the second position. Sort the data from small to large by analogy///</summary>//<param name= "Arry" ></param>//<param N Ame= "Length" ></param> public static void Selectesort (int[] arry,int length) {for (int i= 0;i<length;i++) {//define the minimum value of subscript int minindex = i; for (int j=i+1;j<length;j++) {if (Arry[j] < Arry[minindex]) Minindex = j; }//Swap swap (Arry, minindex, i); }}///<summary>//Exchange two values///</summary>//<param name= "Arry" >< ;/param>//<param name= "I" ></param>///<param Name= "J" ></param> Public static void Swap (int[] Arry,int i,int j) {int tmp = Arry[i]; Arry[i] = Arry[j]; ARRY[J] = tmp; } }}
Because of the two for loops, the time complexity is O (n^2), which is a simple but very slow sort.
Selection and sequencing of algorithms and data structures