Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Level-I/mergeSort.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// JavaScript program for Merge Sort
merge(arr, l, m, r) {
function merge(arr, l, m, r) {
var n1 = m - l + 1;
var n2 = r - m;

var L = new Array(n1);
var R = new Array(n2);

for (var i = 0; i < n1; i++) L[i] = arr[l + i];
for (var j = 0; j < n2; j++) R[j] = arr[m + 1 + j];
for (var j = 0; j < n2; j++) R[j] = arr[m + l + j];

var i = 0;

Expand Down Expand Up @@ -50,16 +50,16 @@ function mergeSort(arr, l, r) {
}

function printArray(A, size) {
for (var i = 0; i < size; i++) console.log(A[i] + " ");
for (var i = 0; i < size; i++) document.write(A[i] + " ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no document specified

}

var arr = [12, 11, 13, 5, 6, 7];
var arrSize = arr.length;
var arr_Size = arr.length;

console.log("Given array is: ");
printArray(arr, arr_size);
document.write("Given array is: ");
printArray(arr, arr_Size);

mergeSort(arr, 0, arr_size - 1);
mergeSort(arr, 0, arr_Size - 1);

console.log("Sorted array is: ");
printArray(arr, arr_size);
document.write("Sorted array is: ");
printArray(arr, arr_Size);