Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit 4370905

Browse files
committed
Added Insertion Sort
1 parent 2bcc7b0 commit 4370905

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

js/Problems/insertion_sort.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Problem: 147. Insertion Sort List
3+
*
4+
* Definition for singly-linked list.
5+
*/
6+
function ListNode(val, next) {
7+
this.val = (val===undefined ? 0 : val)
8+
this.next = (next===undefined ? null : next)
9+
}
10+
11+
/**
12+
* @param {ListNode} head
13+
* @return {ListNode}
14+
*/
15+
var insertionSortList = function (head) {
16+
let sortedHead = head.val;
17+
for (let index = 0; index < head.length; index++) {
18+
if (head) {
19+
20+
}
21+
22+
}
23+
return sortedHead;
24+
};
25+
26+
module.exports = { insertionSortList };

js/Tests/insertion_sort.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const insertion_sort = require('../Problems/insertion_sort');
2+
3+
test("TestPalindrom", () => {
4+
expect(insertion_sort.insertionSortList([4,2,1,3])).toEqual([1,2,3,4]);
5+
});

0 commit comments

Comments
 (0)