Insertion Sort List
来源:互联网 发布:vb.net 高级编程 pdf 编辑:程序博客网 时间:2024/06/16 09:32
链表插入排序
插入排序的原理是,前半部分链表是有序的,遍历原链表,将每个节点插入到前面的有序链表中。
ListNode* insertionSortList(ListNode* head) { if(head == NULL || head->next == NULL) { return head; } ListNode* p = head->next; ListNode* p_next = NULL; ListNode* sorted_list = head; sorted_list->next = NULL; while(p != NULL) { p_next = p->next; sorted_list = insertOneNode(sorted_list, p); p = p_next; } return sorted_list; } ListNode* insertOneNode(ListNode* head, ListNode* node) { ListNode* p = head; ListNode* pre = NULL; while(p != NULL) { if(p->val > node->val) { if(pre == NULL) { node->next = head; return node; } else { pre->next = node; node->next = p; return head; } } pre = p; p = p->next; } pre->next = node; node->next = NULL; return head; }
阅读全文
0 0
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List
- Leetcode: Insertion Sort List
- [LeeCode] Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- [LeetCode] Insertion Sort List
- list - insertion sort - AC
- Krpano插件--event事件注释
- Bootstrap Table使用整理(一)
- TensorFlow 训练 MNIST 数据
- 配置表的处理方式
- ESXi对接iscsi存储操作指南
- Insertion Sort List
- E
- CI框架cli命令行
- cookie & session
- [web前端学习笔记]定位的盒子居中显示
- Windows服务(Windows Service,system权限)程序显示界面与用户交互(xp,win7通用)
- Go语言学习之mime包(the way to go)
- PAT乙级 1038.统计同成绩学生(20)
- Bootstrap Table使用整理(二)