-
快速排序
- #include <cstdio>
- #define ARRLEN(x) (sizeof(x)/sizeof(int))
- int partition(int a[], int low, int high)
- {
- int pivotkey=a[low];
- while (low<high)
- {
- while (low<high && a[high]>=pivotkey)
- --high;
- if (low<high)
- a[low++]=a[high];
- while (low<high && a[low]<=pivotkey)
- ++low;
- if (low<high)
- a[high--]=a[low];
- }
- a[low]=pivotkey;
- return low;
- }
- void quicksort(int a[], int low, int high)
- {
- int pivotpos;
- if (low<high)
- {
- pivotpos=partition(a,low,high);
- quicksort(a,low,pivotpos-1);
- quicksort(a,pivotpos+1,high);
- }
- }
- int main()
- {
- int a[]={2,7,9,3,1,4,8,0,6,2};
- int i;
- for (i=0; i<ARRLEN(a); printf("%2d",a[i]),++i);
- printf("/n");
- quicksort(a,0,ARRLEN(a)-1);
- for (i=0; i<ARRLEN(a); printf("%2d",a[i]),++i);
- printf("/n");
- return 0;
- }
-
相关阅读:
webim-界面细节调整
使用PHP得到所有的HTTP请求头_还有应答头
Bootstrap学习的点点滴滴
asterisk中eyebeam与移动的IMS帐号对接
总结Ajax跨域调用问题
Spring【基础】-注解-转载
Spring-【高阶】注解-转载
让你的IDEA倍爽
IDEA的git密码修改
Idea设置签名
-
原文地址:https://www.cnblogs.com/small-strong/p/3922276.html
Copyright © 2020-2023
润新知