Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created January 1, 2017 20:39
Show Gist options
  • Save orcaman/4d681a9aef6acc16730b16169a005cd2 to your computer and use it in GitHub Desktop.
Save orcaman/4d681a9aef6acc16730b16169a005cd2 to your computer and use it in GitHub Desktop.
MergeSort.go
// MergeSort sorts the slice s using Merge Sort Algorithm
func MergeSort(s []int) []int {
if len(s) <= 1 {
return s
}
n := len(s) / 2
var l []int
var r []int
l = MergeSort(s[:n])
r = MergeSort(s[n:])
return merge(l, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment