Created
July 13, 2018 03:19
-
-
Save hankliu5/025b324eb85c1a0c780a922f740dd9e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func MultiMergeSort(data []float64, res chan []float64) { | |
if len(data) < 2 { | |
res <- data | |
return | |
} | |
leftChan := make(chan []float64) | |
rightChan := make(chan []float64) | |
middle := len(data) / 2 | |
go MultiMergeSort(data[:middle], leftChan) | |
go MultiMergeSort(data[middle:], rightChan) | |
ldata := <-leftChan | |
rdata := <-rightChan | |
close(leftChan) | |
close(rightChan) | |
res <- Merge(ldata, rdata) | |
return | |
} | |
func RunMultiMergeSort(data []float64) (multiResult []float64) { | |
res := make(chan []float64) | |
go MultiMergeSort(data, res) | |
multiResult = <-res | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment