Skip to content

Instantly share code, notes, and snippets.

@sagivo
Last active August 29, 2015 14:14
Show Gist options
  • Save sagivo/deac2d4de0eb186c4527 to your computer and use it in GitHub Desktop.
Save sagivo/deac2d4de0eb186c4527 to your computer and use it in GitHub Desktop.
mergesort and mergesortasync in go
func mergeSortAsync(l []int, c chan []int) {
if len(l) < 2 {
c <- l
return
}
mid := len(l) / 2
c1 := make(chan []int, 1)
c2 := make(chan []int, 1)
go mergeSortAsync(l[:mid], c1)
go mergeSortAsync(l[mid:], c2)
go func() { c <- merge(<-c1, <-c2) }()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment