package main
import (
"fmt"
"math/rand"
"time"
)
func sleepAndPrint(i int, ch chan int) {
time.Sleep(time.Nanosecond * time.Duration(i))
ch <- i
}
func sleepSort(arr []int) []int {
ch := make(chan int)
res := make([]int, len(arr))
for _, v := range arr {
go sleepAndPrint(v, ch)
}
for i := 0; i
res[i] = <-ch
}
return res
}
func main() {
arr := make([]int, 256)
for i := range arr {
arr[i] = rand.Intn(100)
}
fmt.Println(arr)
sortedArr := sleepSort(arr)
fmt.Println(sortedArr)
}
[81 87 47 59 81 18 25 40 56 0 94 11 62 89 28 74 11 45 37 6 95 66 28 58 47 47 87 88 90 15 41 8 87 31 29 56 37 31 85 26 13 90 94 63 33 47 78 24 59 53 57 21 89 99 0 5 88 38 3 55 51 10 5 56 66 28 61 2 83 46 63 76 2 18 47 94 77 63 96 20 23 53 37 33 41 59 33 43 91 2 78 36 46 7 40 3 52 43 5 98 25 51 15 57 87 10 10 85 90 32 98 53 91 82 84 97 67 37 71 94 26 2 81 79 66 70 93 86 19 81 52 75 85 10 87 49 28 18 84 3 24 47 12 32 16 39 40 86 51 76 40 51 44 64 5 83 1 90 2 58 67 31 78 54 22 23 42 8 43 68 66 10 35 40 4 62 57 15 71 39 30 13 0 59 20 83 70 84 47 10 65 62 29 20 48 56 95 66 0 56 29 92 31 77 86 20 99 62 47 92 88 11 3 88 18 56 19 7 57 52 75 81 53 95 17 93 70 96 86 32 20 60 22 29 61 60 20 79 54 64 60 51 81 57 16 0 39 37 33 61 4 85 9 15 19 14]
최고의 정렬 알고리즘