fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6. "math/rand"
  7. "sort"
  8. )
  9.  
  10. const ARRAY_LENGTH = 100
  11.  
  12. func f(n int, r chan int) {
  13. time.Sleep(time.Duration(n) * time.Millisecond)
  14. r <- n
  15. }
  16.  
  17. func main() {
  18. a := []int{}
  19. for i:=0; i<ARRAY_LENGTH; i++ {
  20. a = append(a, rand.Intn(ARRAY_LENGTH * 100))
  21. }
  22.  
  23. r := make(chan int)
  24.  
  25. for _, i := range a {
  26. go f(i, r)
  27. }
  28.  
  29. b := []int{}
  30. for _ = range a {
  31. b = append(b, <-r)
  32. }
  33.  
  34. fmt.Println("is sorted?", sort.IntsAreSorted(b))
  35. }
Success #stdin #stdout 0s 790016KB
stdin
Standard input is empty
stdout
is sorted? true