leetcode之Insertion Sort List
来源:互联网 发布:艾滋病感染概率 知乎 编辑:程序博客网 时间:2024/05/21 00:19
Sort a linked list using insertion sort.
此题较简单,就是练习链表增删查问题
class Solution {public: ListNode *insertionSortList(ListNode *head) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if(NULL == head || NULL==head->next) return head; ListNode *p = head->next, *q, *trace,*pre, *curPre = head; while(p){ trace = head; pre = NULL; q = p->next; while(trace != p){ //从头节点开始查找节点值是否有比当前节点p值大的 if(trace->val > p->val){ if(NULL == pre){ curPre->next = p->next; p->next = head; head = p; break; } curPre->next = p->next; p->next = pre->next; pre->next = p; break; } pre = trace; trace = trace->next; } //如果p节点被插入到前面的节点中 if(trace != p){ p = q; } else{ curPre = p; p=p->next; } } return head; }};
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- LeetCode之Insertion Sort List
- leetcode之insertion Sort list
- leetcode之insertion-sort-list
- leetcode之insertion-sort-list
- leetCode解题报告之Insertion Sort List
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- JDBC为数据连接池铺垫1
- smtp 发送邮件 乱码解决
- getContextPath、getServletPath、getRequestURI的区别
- uva11396 - Claw Decomposition
- 多线程时钟模拟
- leetcode之Insertion Sort List
- linux下实现串口通讯
- JSF —— Facelets 标签
- HDU-1043 Eight 八数码问题
- Spirng3基于注解(annotation)整合ehcache 使用页面缓存、对象缓存
- 数据库索引的作用和优点缺点
- 最小步数nyoj--92
- 算法实战5:多种数据结构实现四则运算
- 相似度计算