Insert sort includes: Direct insert sort and hill sort.
The specific code is as follows:
Direct Insert Sort:
/// <summary> ///Direct Insert Sort///sorting for a small number of elements///Stability: Stable///complexity of Time: O (n2)/// </summary> Public Static voidSimpinsertsort (int[] Array) { inttemp =0; for(inti =1; I < array. Length; i++) { if(Array[i] < array[i-1]) {temp=Array[i]; intj =0; for(j = i-1; J >=0&& temp < ARRAY[J]; j--) {array[j+1] =Array[j]; } array[j+1] =temp; } } }
Hill Sort:
/// <summary> ///Hill Sort Narrow incremental sort///is an improved version of the direct insert sort///Stability: unstable///Average time complexity: O (nlog2n), worst case O (N1.5)/// </summary> Public Static voidShellsort (int[] Array) { intGap = array. Length/2; while(Gap >0) { //Direct Insert Sort for(inti =0; I < gap; i++) { for(intj = i + gap; J < Array. Length; J + =Gap) { if(Array[j] < array[j-Gap]) { inttemp =Array[j]; intK = J-Gap; while(k >=0&& Array[k] >temp) {Array[k+ Gap] =Array[k]; K-=Gap; } array[k+ Gap] =temp; }}} Gap= Gap/2; }; }
Insert Sort-c# Implementation