leetcode - Insertion Sort List
2013-11-20 14:41
281 查看
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *insertionSortList(ListNode *head) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if (head == NULL || head->next == NULL) return head; ListNode * itr =head->next; head->next = NULL; while (itr != NULL){ ListNode * node = head, * last =NULL; ListNode *next = itr->next; while ((node != NULL) && (node->val < itr->val)){ last = node; node = node->next; } itr->next = node; if (node == head) head = itr; else last->next = itr; itr = next; } return head; } };
相关文章推荐
- leetcode InsertionSort list
- [C++]LeetCode: 126 Insertion Sort List (插入排序链表)
- Leetcode Insertion Sort List
- leetcode之Insertion Sort List
- LeetCode-Insertion Sort List[AC源码]
- LeetCode147: Insertion Sort List
- [leetcode147]insertion sort list
- [Leetcode][python]Insertion Sort List
- [Leetcode]#147 Insertion Sort List
- Insertion Sort List(leetcode)
- LeetCode-Insertion Sort List-链表插入排序-链表操作
- LeetCode 147 — Insertion Sort List(C++ Java Python)
- 【leetcode】insertion-sort-list
- LeetCode(2):insertion-sort-list
- LeetCode Insertion Sort List
- LeetCode 147 Insertion Sort List
- Insertion Sort List -- LeetCode
- LeetCode | Insertion Sort List
- [leetcode] Insertion Sort List
- 【LeetCode】Insertion Sort List