【leetcode】插入排序一个链表
来源:互联网 发布:安卓模拟器 for mac 编辑:程序博客网 时间:2024/05/21 09:21
ListNode* insertionSortList(ListNode* head){ ListNode * new_head = new ListNode(0); new_head->next = head; ListNode* pre = new_head; ListNode*cur = head; while (cur) { if (cur->next&&cur->next->val < cur->val) { while (pre->next&&pre->next->val < cur->next->val) { pre = pre->next;//要插入需要找到正确位置的前一个位置 } //穿针引线改变指针的指向 ListNode* temp = pre->next; pre->next = cur->next; cur->next = cur->next->next; pre->next->next = temp; pre = new_head; } else { cur = cur->next; } } ListNode*res = new_head->next; delete new_head; return res;}
0 0
- 【leetcode】插入排序一个链表
- leetcode 刷题:插入排序链表
- [LeetCode]147 链表插入排序
- 使用插入算法排序链表,leetcode
- 对一个链表的插入排序
- Insertion Sort List 链表插入排序@LeetCode
- LeetCode:Insertion Sort List//链表插入排序
- leetcode Insertion Sort List(链表插入排序)
- LeetCode | Insertion Sort List(插入法排序链表)
- [C++]LeetCode: 126 Insertion Sort List (插入排序链表)
- Leetcode Insertion Sort List 插入排序链表
- LeetCode Insertion Sort List 链表的插入排序
- LeetCode 147 Insertion Sort List(链表插入排序)
- leetcode 147. Insertion Sort List-链表插入排序
- leetcode钻研5 链表的插入排序
- [LeetCode] Insertion Sort List 单向链表插入排序
- LeetCode-147. Insertion Sort List (JAVA)链表插入排序
- leetcode 147. Insertion Sort List 链表插入排序
- python_nba_tree
- 数组
- 20170429C语言指针二
- VS2017出现: Microsoft C++ 异常: cv::Exception,位于内存位置 0x000000D99016F6B0 处。
- 链表
- 【leetcode】插入排序一个链表
- Redis与Memcached的区别(二)
- JavaScript 脚本语言 重点整理
- HDU
- hdu[2034]
- 在配置XML文件时出现reference file contains errors (http://www.springframework.org/schema/beans/...解决方案
- 阿里云ECS创建vsftpd后,用户无法正常登录
- 串操作
- mhn安装时提示SQL: u'INSERT INTO rule_references 错误