标签:
Title:
Sort a linked list using insertion sort.
class Solution { public: ListNode *insertionSortList(ListNode *head) { ListNode* sortedHead = new ListNode(0); while (head){ ListNode* cur = sortedHead; ListNode* tmp = head->next; while (cur->next != NULL && cur->next->val < head->val){ cur = cur->next; } head->next = cur->next; cur->next = head; head = tmp; } return sortedHead->next; } };
标签:
原文地址:http://www.cnblogs.com/yxzfscg/p/4530001.html