lintcode 173 链表插入排序
来源:互联网 发布:大连淘车网络和中软卓 编辑:程序博客网 时间:2024/05/17 08:11
1.用插入排序对链表排序
2.小的节点前移,大的节点后移
3.
/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param head: The first node of linked list.
* @return: The head of linked list.
*/
ListNode *insertionSortList(ListNode *head) {
// write your code here
ListNode *dummy=new ListNode(0);
while(head!=NULL)
{
ListNode *node=dummy;
while(node->next!=NULL&&node->next->val<head->val){node=node->next;}
ListNode *temp=head->next;
head->next=node->next;
node->next=head;
head=temp;
}
return dummy->next;
}
};
4.感想
记得老师在群里发过类似这个题的代码,差不多类型的.多看几遍就明白了解题思路.
- lintcode 173 链表插入排序
- LintCode 链表插入排序
- lintcode-链表插入排序
- LintCode-链表插入排序
- 链表插入排序 lintcode
- LintCode 链表插入排序
- 链表插入排序-LintCode
- LintCode 链表插入排序
- 链表插入排序-LintCode
- LintCode(E) 链表插入排序
- Lintcode——链表插入排序
- 【lintcode】——链表插入排序-Insertion Sort List
- lintcode 173 单链表插入排序 python
- LintCode : 链表排序
- lintcode,链表排序
- LintCode 链表排序
- 链表排序-LintCode
- lintcode--链表排序
- RT-Thread: Design pattern of the Producer-consumer model (Semaphore)
- redis特点及windows下安装使用
- 【JQuery】熟能生巧JQuery(一)——目录
- C#复习 2017-3-29
- 1009. 说反话 (20)-PAT乙级
- lintcode 173 链表插入排序
- ESB v6.6中新版本构件库XMLDatabaseUtil不支持中文
- 1005. Spell It Right (20)
- Android优化之插件开发(动态加载Apk)
- 杭电OJ1002
- mybatis逆向工程使用方法
- 记一次Android系统下解决音频UnderRun问题的过程
- 关于随机函数rand()的使用
- python 正则表达式,函数说明