LeeCode-Insertion Sort List
来源:互联网 发布:2016香港经济发展数据 编辑:程序博客网 时间:2024/06/01 09:14
Sort a linked list using insertion sort.
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* insertionSortList(struct ListNode* head) { struct ListNode *p; p=head; int count=0; while(p!=NULL) { count++; p=p->next; } int *array; array=(int *)malloc(count*sizeof(int)); p=head; int i=0,j,k; while(p!=NULL) { array[i]=p->val; p=p->next; i++; } for(i=1;i<count;i++) { for(j=i-1;j>=0;j--) { if(array[j]<array[i]) break; } if(j!=i-1) { int tmp=array[i]; for(k=i-1;k>j;k--) { array[k+1]=array[k]; } array[k+1]=tmp; } } i=0; struct ListNode *q; q=head; while(q!=NULL) { q->val=array[i]; q=q->next; i++; } return head;}
0 0
- [LeeCode] Insertion Sort List
- LeeCode-Insertion Sort List
- LeeCode 148 Sort List
- Insertion Sort List | leetcode
- 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
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- 【最优化方法】穷举法 vs. 爬山法 vs. 模拟退火算法 vs. 遗传算法 vs. 蚁群算法
- LeeCode-Merge Sorted Array
- Emergency(山东省第一届ACM省赛)
- サポートベクターマシン(SVM)
- python logging的简单使用2
- LeeCode-Insertion Sort List
- cuda7.0安装(嵌入式)
- iOS网络编程————POST请求和GET请求
- 冒泡排序的交换次数
- R语言实现文本挖掘和tagxedo词云可视化技术
- [JSOI2016]无界单词
- ニューラルネットワーク
- Python学习笔记11
- Anaconda 下各种第三方库的安装