|
|
|
@ -32,8 +32,8 @@ func Merge(arr []int, l, m, r int){
|
|
|
|
|
j = 0 //Initial index of second subarray
|
|
|
|
|
k = l //Initial index of merged subarray
|
|
|
|
|
|
|
|
|
|
for(i < n1 && j < n2){
|
|
|
|
|
if(L[i] <= R[j]){
|
|
|
|
|
for i < n1 && j < n2 {
|
|
|
|
|
if L[i] <= R[j] {
|
|
|
|
|
arr[k] = L[i]
|
|
|
|
|
i++
|
|
|
|
|
} else {
|
|
|
|
@ -44,14 +44,14 @@ func Merge(arr []int, l, m, r int){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Copy the remaining elements of L[], if there are any
|
|
|
|
|
for(i < n1){
|
|
|
|
|
for i < n1 {
|
|
|
|
|
arr[k] = L[i]
|
|
|
|
|
i++
|
|
|
|
|
k++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Copy the remaining elements of R[], if there are any
|
|
|
|
|
for(j < n2){
|
|
|
|
|
for j < n2 {
|
|
|
|
|
arr[k] = R[j]
|
|
|
|
|
j++
|
|
|
|
|
k++
|
|
|
|
@ -59,7 +59,7 @@ func Merge(arr []int, l, m, r int){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func MergeSort(arr []int, l, r int) {
|
|
|
|
|
if(l < r){
|
|
|
|
|
if l < r {
|
|
|
|
|
//Same as (l + r) / 2 but avoids overflow for large l and h
|
|
|
|
|
var m int = l + (r-l)/2
|
|
|
|
|
|
|
|
|
|