leetcode-147 Insertion Sort List
2015-03-14 12:06
387 查看
题目要求使用插入排序
因为是链表,所以加上一个辅助头节点(这个思想在链表的操作中经常用到)
这题本来是没有什么难度的
因为是链表,所以加上一个辅助头节点(这个思想在链表的操作中经常用到)
这题本来是没有什么难度的
<span style="font-family:Microsoft YaHei;font-size:14px;">/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *insertionSortList(struct ListNode *head) { if(head == NULL) return NULL; struct ListNode helper; struct ListNode *cur; struct ListNode *next; struct ListNode *pre; helper.next = NULL; cur = head; pre = &helper; next = NULL; while(cur != NULL){ next = cur->next; while( (pre->next != NULL) && (pre->next->val < cur->val) ){ pre = pre->next; } cur->next = pre->next; pre->next = cur; pre = &helper; cur = next; } return helper.next; }</span>
相关文章推荐
- Leetcode 147 Insertion Sort List
- 【LeetCode-面试算法经典-Java实现】【147-Insertion Sort List(链表插入排序)】
- leetcode147~Insertion Sort List
- [LeetCode147]Insertion Sort List(链表插入排序)
- [Leetcode 147, medium] Insertion Sort List
- 【leetcode】【单链表】【147】Insertion Sort List
- leetcode 147: Insertion Sort List
- [leetcode 147] Insertion Sort List
- 【leetcode】【单链表】【147】Insertion Sort List
- leetcode_147题——Insertion Sort List(线性表,插入排序)
- LeetCode 147 Insertion Sort List(链表插入排序)
- LeetCode 147 Insertion Sort List
- (Leetcode 147)Insertion Sort List
- [Leetcode] #147 Insertion Sort List
- LeetCode147: Insertion Sort List
- leetcode[147]Insertion Sort List
- [leetcode147]insertion sort list
- [Leetcode]#147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode(147) Insertion Sort List