1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceCocktailsort8 {9 class ProgramTen { One Static voidMain (string[] args) A { - int[] arr =New int[ -]; -Random rd =NewRandom (); the for(inti =0; I < arr. Length; i++) - { -Arr[i] = Rd. Next ( -); - } + Sort (arr); - } + A Public Static voidSort (int[] arr) at { - //need to go back and forth arr. LENGTH/2 Trip - for(inti =0; I < arr. Length/2; i++) - { - //class bubbling, swap maximum to right end - for(intj = i; J < arr. Length-i-1; J + +) in if(Arr[j] > arr[j +1]) -Swap (Arr, J, J +1); to //class bubbling, exchanging minimum to left end + for(intj = arr. Length-i-1; J > i; j--) - if(Arr[j] < arr[j-1]) theSwap (Arr, J, J-1); * } $ foreach(intIincharr)Panax Notoginseng Console.WriteLine (i); - } the + Public Static voidSwap (int[] arr,intLeftintRight ) A { the inttemp =Arr[left]; +Arr[left] =Arr[right]; -Arr[right] =temp; $ } $ } -}
Sort eight: Cocktail sort