Just Sort It(快速排序)
来源:互联网 发布:淘宝店粉丝怎么看 编辑:程序博客网 时间:2024/06/05 09:04
Judge Info
- Memory Limit: 1124KB
- Case Time Limit: 10000MS
- Time Limit: 10000MS
- Judger: Number Only Judger
Description
Sorting is one of the most important algorithm in computer sciences. Please learn it well.
本题需要的排序算法复杂度应该为nlogn,冒泡、选择的负责度为n^2,快排、归并、堆排序的复杂度为nlogn
本题的内存限制也是比较严格,所以建议大家使用堆排序,或者快速排序
Input
The first line of input contains , the number of test cases. There is only line for each test case. The first numberof each test case will indicates how many integer numbers are there for sort from smaller to larger. All numbers are in the range of .
Output
Output one line for every test case. The result of those integer numbers after sorting.
Sample Input
33 3 2 12 3 23 5 4 3
Sample Output
1 2 32 33 4 5
标准快排
#include<stdio.h>void quicksort(int *s, int l, int r){ if (l < r) { int i = l, j = r, x = s[l]; while (i < j) { while(i < j && s[j] >= x) j--; if(i < j) s[i++] = s[j]; while(i < j && s[i] < x) i++; if(i < j) s[j--] = s[i]; } s[i] = x; quicksort(s, l, i - 1); quicksort(s, i + 1, r); }}int main(){int t;scanf("%d",&t);while(t--){int n;int a[250000];scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);quicksort(a,0,n-1);for(int i=0;i<n;i++){printf("%d",a[i]);if(i<n-1)putchar(' ');}putchar('\n');}return 0;}
0 0
- Just Sort It(快速排序)
- 快速排序(quick sort)
- 快速排序(quick sort)
- 快速排序(quick sort)
- 快速排序(Quick Sort)
- 快速排序(Quick sort)
- 快速排序(Quick Sort)
- 快速排序(Quick Sort)
- 快速排序(Quick Sort)
- 快速排序(Quick Sort)
- 快速排序(Quick Sort)
- Quick Sort(快速排序)
- 快速排序(quick sort)
- 快速排序(Quick-Sort)
- 排序算法---快速排序(Quick Sort)
- hdoj Sort it 2689 (归并排序)
- 快速排序源码(quick sort)
- 快速排序算法(Quick Sort)
- VMware双网卡实现虚拟机连开发板和Internet
- 行测笔记
- Pseudoprime numbers poj3641(快速幂+素数判定)
- 嵌入式 最全面的linux信号量解析
- 判断一个单链表是否有环及环的链接点
- Just Sort It(快速排序)
- exec函数簇理解
- 【Game】组合游戏入门
- Call to undefined function mb_detect_encoding() 错误
- 线段树总结
- ios--UITabBarController代理的使用
- WP_Query的使用方法
- python使用pygal进行绘制数据图表和监控图表
- reinterpre_cast用法