Skip to content

Commit

Permalink
Insertion sort in an array in js completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamabhiCH committed Mar 8, 2024
1 parent d1f9414 commit 7dd1831
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions arr_ins_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,22 @@

const arr = [67,12,45,7,30,80,56,1,22];

function insertionSort(arr){
let n = arr.length;
let k;

let i,j;
for(i = 0; i < n; i++){
k = arr[i];
j = i - 1;
for(j; j >= 0, arr[j]>k; --j){
arr[j+1] = arr[j];
}
arr[j+1] = k;
}
}


console.log("Original Array : ",arr);
insertionSort(arr);
console.log("Selection Array : ",arr);

0 comments on commit 7dd1831

Please sign in to comment.