147. Insertion Sort List
来源:互联网 发布:淘宝省钱群骗局 编辑:程序博客网 时间:2024/04/20 21:45
Sort a linked list using insertion sort.
Subscribe to see which companies asked this question
/** * 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) { if(NULL == head) return head; ListNode* newhead=head; head=head->next; newhead->next = NULL; while(head) { ListNode* next=head->next; head->next=NULL; ListNode* temp= newhead; if(newhead->val >= head->val) { head->next=newhead; temp = head; } else { ListNode* pretemp=NULL; while(newhead) { if(head->val<=newhead->val) { pretemp->next=head; head->next=newhead; // pretemp=head; break; } pretemp=newhead; newhead=newhead->next; } if(newhead==NULL) { pretemp->next=head; // head->next=NULL; } } head = next; newhead=temp; } return newhead; }};
0 0
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- centos6添加php扩展但没有phpize,安装php-devle遇到错误
- #尺取法 --由codeforces 701C They are EveryWhere为例
- Linux内核学习的一些国外网站
- 使用charles无法抓取到iOS Simulator的请求数据包
- 模板容器类及迭代器的实现二(基于链表)
- 147. Insertion Sort List
- html往js文件传递参数
- 很赞的JSF参考教程,走不路过,不要错过
- python3 匹配任意字符
- selenium中sendKeys对于不同版本的实现
- javaweb学习总结(十四)——JSP原理
- Jquery vaildate 自定义验证图片大小和类型
- 关于部分手机app安装失败或安装未成功的原因
- 自定义navigationitem时,button的状态颜色问题