This is a creation in Article, where the information may have evolved or changed.
Package Mainimport "FMT"//Threads thread identity creation thread number func quicksort (nums []int, ch Chan int, level int, threads int) {Level=le vel*2 If Len (nums) = = 1 {ch<-nums[0]; close (CH); return}//ch<-nums[0] indicates that the nums[0] data is written to the CH channel if Len (nums) = = 0 { Close (CH); return} Less: = "make" ([]int, 0)//Greater: = Make ([]int,0) Left: = Nums[0]//Fast sort Axis Nums = nums[1:]//scan data to the right of the axis Put in the greater less than the for _,num_data: = range nums{switch{case num_data <= left:less = append (less,num_d ATA) Case Num_data > left:greater = Append (Greater,num_data)}} left_ch: = Do (chan int, len (less)) Right_ch: = Make (chan int, Len (greater)) if (level <= threads) {Go quicksort (less, left_ch, level, threads)//Sub-task Go quicksort (Greater,right_ch, level, threads)}else{quicksort (less,left_ch, level, threads) quicksort (Greater, Right_ch, level, threads)}//merge data for I: = Range left_ch{ch<-i; } ch<-left for I: = Range right_ch{ch<-i;} close (CH) return}func Main () {x: = []int{3, 1, 4, 1, 5, 9, 2, 6} ch: = make (chan int) go quicksort (x, ch, 0, 0)//0 0 means no limit on the number of threads for V: = Range (ch) {FMT. Println (v)}}