对一个链表的插入排序
来源:互联网 发布:北bi数据分析 编辑:程序博客网 时间:2024/05/21 15:46
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* insertionSortList(struct ListNode* head) {
struct ListNode *node=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* cur;
struct ListNode* tmp;
struct ListNode* pre;
struct ListNode* end;
node->next=head;
if(head!=NULL&&head->next!=NULL){
cur=head->next;
end=head;
while(cur!=NULL){
pre=node;
if (cur->val>=end->val){
end=cur;
}
else{
while(cur->val>=pre->next->val){
pre=pre->next;
}
tmp=pre->next;
end->next=cur->next;
pre->next=cur;
cur->next=tmp;
}
cur=end->next;
}
}
return node->next;
}
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* insertionSortList(struct ListNode* head) {
struct ListNode *node=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* cur;
struct ListNode* tmp;
struct ListNode* pre;
struct ListNode* end;
node->next=head;
if(head!=NULL&&head->next!=NULL){
cur=head->next;
end=head;
while(cur!=NULL){
pre=node;
if (cur->val>=end->val){
end=cur;
}
else{
while(cur->val>=pre->next->val){
pre=pre->next;
}
tmp=pre->next;
end->next=cur->next;
pre->next=cur;
cur->next=tmp;
}
cur=end->next;
}
}
return node->next;
}
0 0
- 对一个链表的插入排序
- 对链表排序,用插入排序
- [学习总结][算法]用插入排序对一个链表进行排序
- 对给定链表进行插入排序。
- 对链表数据进行插入排序
- 对一个已排序的数组插入一个新的数字排序
- 对插入排序的理解
- 【leetcode】插入排序一个链表
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 链表的插入排序
- 对插入排序算法的测试
- javascript基础知识的重要性
- 深度行研:危机四伏的传统健身馆,如何杀出一条血路
- Rtabmap build errors
- 利用FormData异步提交content-type为jpg,等流方面信息 --2016.04.20
- Mysql读写分离配置
- 对一个链表的插入排序
- [leetcode]Serialize and Deserialize Binary Tree
- git基本使用
- 一组数据中只有一个数字出现了一次。 其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- Netty UDP demo
- JavaScript中类似java常量constants使用方法
- 国内常用的Android镜像下载地址(附教育网主要镜像站)
- 总结c++类的构造函数 拷贝构造函数 析构函数 赋值运算符重载的特点以及函数调用顺序
- matlab 定时器