Insertion Sort List
来源:互联网 发布:数据库exists 编辑:程序博客网 时间:2024/05/21 06:27
Insertion Sort List
Sort a linked list using insertion sort.
Subscribe to see which companies asked this question.
插入排序,注意指针的指向
代码:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* insertionSortList(ListNode* head) { ListNode* first,*second; ListNode* hhead; if (head==NULL) return NULL; first=head; hhead=new ListNode(INT_MIN); second=hhead; hhead->next=head; ListNode* cur=head->next; head->next=NULL; int len=1; while(cur) { ListNode* temp=cur->next; cur->next=NULL; second=hhead; first=second->next; int flag=0; for (int i=0; i<len; i++) { if (((cur->val)>=(second->val))&&((cur->val)<=(first->val))) { cur->next=first; second->next=cur; flag=1; break; } else { second=first; first=first->next; } } if (flag==0) { second->next=cur; } cur=temp; len++; } return hhead->next; }};
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
- HDFS架构设计
- empty与isset的差别比较
- MFC HMODULE
- 自定义数据绑定---HandlerMethodArgumentResolver
- LeetCode之Reverse Words in a String III
- Insertion Sort List
- 阻塞与非阻塞,同步与异步
- 无人驾驶中的决策规划控制技术
- maven的jar文件配置
- 队列及其实现
- Spinner控件的学习
- markdownppad使用记录
- DeepID训练过程中loss居高不下解决方法
- 浅谈前端跨域的几种解决方式