1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceShellsort8 {9 class ProgramTen { One Static voidMain (string[] args) A { - int[] arr =New int[Ten]; -Random rd =NewRandom (); the for(inti =0; I < arr. Length; i++) - { - //Arr[i] = Rd. Next (ten); -Arr[i] = arr. Length-i; + } - Shellsort (arr); + foreach(intIincharr) A Console.WriteLine (i); at } - - Public Static voidShellsort (int[] arr) - { - inttemp, k; - intLen = arr. Length/2; in for(intGap = Len; Gap >0; Gap/=2) - { to for(intj = Gap; J < arr. Length; J + +) + { -temp =Arr[j]; theK = J-Gap; * while(k >=0&& Arr[k] >temp) $ {Panax NotoginsengArr[k + gap] =Arr[k]; -K-=Gap; the } +ARR[K+GAP] =temp; A } the } + } - $ Public Static voidSwap (int[] arr,intAintb) $ { - inttemp =Arr[a]; -Arr[a] =Arr[b]; theARR[B] =temp; - }Wuyi } the}
Sort six: Hill sort