LintCode_173 链表插入排序
生活随笔
收集整理的這篇文章主要介紹了
LintCode_173 链表插入排序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目
用插入排序?qū)︽湵砼判?/p>
樣例
Given?1->3->2->0->null, return?0->1->2->3->null
C++代碼
ListNode *insertionSortList(ListNode *head) {// write your code hereif (!head) return NULL;ListNode* root = head;head = head->next;root->next = NULL;ListNode* p;while (head){p = head;head = head->next;p->next = NULL;ListNode* t, *ft;ft = t = root;if (root->val >= p->val){p->next = root;root = p;}else{while (t && t->val < p->val){ft = t;t = t->next;}if (!t) ft->next = p;else{ft->next = p;p->next = t;}}}return root; }
轉(zhuǎn)載于:https://www.cnblogs.com/Smallhui/p/5456876.html
總結(jié)
以上是生活随笔為你收集整理的LintCode_173 链表插入排序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原生JS封装Ajax插件(同域jsonp
- 下一篇: Android 高手进阶之自定义View