Added insertion sort algorithm in js and updated README (#37)

* Added insertion sort algorithm in javascript

* listed sorting algorithm in javascript in README.md
pull/41/head
Roshan Kumar 2021-01-28 21:44:53 +05:30 committed by GitHub
parent 4c9fab8025
commit c7f4950ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -26,4 +26,6 @@
### JavaScript ### JavaScript
1. [Bubble Sort](js/bubble-sort.js) 1. [Bubble Sort](js/bubble-sort.js)
2. [Insertion Sort](js/insertion-sort.js)
3. [Selection Sort](js/selection-sort.js)

View File

@ -0,0 +1,13 @@
let sort = [12,6,3,88,1,4,8];
for(let i = 0; i<sort.length; i++){
let key = sort[i];
let j = i-1;
//comparing keys with other elements
while(key<sort[j] && j>=0){
sort[j+1]=sort[j];
j--;
}
sort[j+1]=key;
}
console.log(sort)