Skip to content

Commit 314c74a

Browse files
author
Ahmed Ashraf Muhammed
committed
Insertion Sort Algorithm
1 parent 2c810f2 commit 314c74a

File tree

1 file changed

+17
-0
lines changed
  • Insertion Sort Algorithm

1 file changed

+17
-0
lines changed

Insertion Sort Algorithm/app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function getValues() {
2+
insertionSortAlgorithm([9, 1, 4, 5])
3+
})();
4+
5+
6+
function insertionSortAlgorithm(x) {
7+
for (let i = 1; i < x.length; i++) {
8+
let key = x[i];
9+
for (var j = i - 1; j >= 0; j--) {
10+
if (x[j] > key) x[j + 1] = x[j]
11+
else break;
12+
};
13+
x[j + 1] = key;
14+
}
15+
console.log(x);
16+
};
17+

0 commit comments

Comments
 (0)