[leetcode] Insertion Sort List
来源:互联网 发布:精致的利己主义 知乎 编辑:程序博客网 时间:2024/05/20 05:59
#include<iostream>using namespace std;struct ListNode{ int value; ListNode* next; ListNode(int value):value(value),next(NULL){};};ListNode* Insertsort(ListNode* head){ if(!head) return NULL; ListNode* dump=new ListNode(INT_MIN); dump->next=head; bool flag=false; for(ListNode* pre=dump;pre->next!=NULL;) { ListNode* p=NULL; for(ListNode* cur=dump;cur!=pre->next;p=cur,cur=cur->next) { if(pre->next->value>cur->value) { continue; } p->next=pre->next; pre->next=pre->next->next; p->next->next=cur; flag=true; break; } if(!flag) pre=pre->next; else flag=false; } return dump->next;}void main(){ int a[10]={2,5,1,5,3,2,4,9,8,1}; ListNode* head=new ListNode(a[0]); ListNode* cur=head; for(int i=1;i<10;i++) { ListNode* node=new ListNode(a[i]); cur->next=node; cur=cur->next; } head=Insertsort(head); while(head) { cout<<head->value<<' '; head=head->next; }}
0 0
- 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
- [LeetCode] Insertion Sort List
- Insertion Sort List (LeetCode)
- [LeetCode] Insertion Sort List
- [LeetCode]Insertion Sort List
- leetcode Insertion Sort List
- Insertion Sort List -- LeetCode
- Insertion Sort List (LeetCode)
- LeetCode Insertion Sort List
- leetcode Insertion Sort List
- MySQL入门
- 史上最全的CSS hack方式一览
- mac之ssh免登陆验证、ssh-keygen
- ios 拍照 照片过小 UIImagePickerController
- 大学4年,毕业后迎接你的不应该是各种培训班
- [leetcode] Insertion Sort List
- MySQL使用拾遗
- 2012年5月SAT香港真题解析
- 闪存存储系统综述的总结
- ssh: connect to host localhost port 22: Connection refused
- NOI2015结束,从此我要全力以赴奋战OI
- oracle sql 按某个字段分组然后从每组取出最大的一条纪录
- 用java语言编写一个可以求20个范围在1-100之间随机整数和的程序。
- jquery的ajax 处理后台传来json格式的二维数组