-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path173.h
36 lines (34 loc) · 897 Bytes
/
173.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param head: The first node of linked list.
* @return: The head of linked list.
*/
ListNode * insertionSortList(ListNode * head) {
// write your code here
ListNode *array_index = head;
while(array_index != nullptr){
ListNode *array_begin = head;
while(array_begin != nullptr && array_begin != array_index){
if(array_begin->val > array_index->val){
swap(array_begin->val, array_index->val);
}
array_begin = array_begin->next;
}
array_index = array_index->next;
}
return head;
}
};