1. Insert Sort
namespaceInsert Sort {//the insertion sort is much faster when it is probably ordered, such as: 3,1,7,4,5,9,10,15,12//This, you will find that it is probably already ascending, when inserting fast,//the speed is almost the same as the other sort. classProgram {Static voidMain (string[] args) { int[] arr = { -, A, About, +,12125, About, -,212, $,787, +, A, About, $};//Array to sortInsertsort (arr);//Call the Insert Sort function foreach(intItemincharr) Console.WriteLine (item); } Private Static voidInsertsort (int[] arr) { //The insertion sort is to insert a sequence of numbers into an ordered number//The default subscript is 0 This number is already ordered for(inti =1; I < arr. Length; i++) { intInsertval = Arr[i];//First, remember the number that you want to insert. intInsertindex = i-1;//Find out the subscript of the previous number (wait for the number of inserts to be compared to this number)//If this condition is met, it is stated that we have not found the proper location while(Insertindex >=0&& Insertval < Arr[insertindex])//here Small Yu Shi order, big so descending{Arr[insertindex+1] = Arr[insertindex];//and move the number larger than the number of inserts backwardsinsertindex--;//The pointer continues to move backwards, and the number of inserts is compared to the number pointed to by the pointer. } //Insert (this time to insertval find the appropriate location)Arr[insertindex +1] =Insertval; } } }}
Summary of the introduction of algorithms