微软等数据结构+算法面试100题(12)--快速排序
2012-11-10 12:43
429 查看
/* 3.快速排序(东软喜欢考类似的算法填空题,又如堆排序的算法等) */ int Parition(int *p,int low,int high) { int pivotkey=p[low]; while(low<high) { while((low<high)&&(p[high]>=pivotkey))//这里相等不能丢掉 high--; p[low]=p[high]; while((low<high)&&(p[low]<=pivotkey)) low++; p[high]=p[low]; } p[low]=pivotkey; return low; } void QuickSort(int *p,int low,int high) { if(low>=high) return; int pivot=Parition(p,low,high); QuickSort(p,low,pivot-1); QuickSort(p,pivot+1,high); }
void QuickSortTest() { int p[]={10,0,15,12,-10,-5,9,2,8,6,4,20,19,6,8,7}; int len=sizeof(p)/sizeof(int); cout<<"the array : "; ShowArray(p,len); cout<<"after sort : "; QuickSort(p,0,len-1); ShowArray(p,len); }
相关文章推荐
- 微软等数据结构+算法面试100题(43)-- 把二元查找树转变成排序的双向链表
- [置顶]横空出世,席卷互联网--评微软等公司数据结构和算法面试100题
- [整理III]微软等数据结构+算法面试100题[最新第61-80题]
- 微软等数据结构+算法面试100题全部答案集锦
- 互联网--评微软等公司数据结构和算法面试100题 .
- 微软等数据结构+算法面试100题全部答案集锦
- 横空出世,席卷互联网--评微软等公司数据结构和算法面试100题
- [整理III]微软等数据结构+算法面试100题[最新第61-80题]
- 微软等数据结构+算法面试100题(6)--写一个函数,检查字符是否是整数,如果是,返回其整数值
- 微软等数据结构+算法面试100题(39)-- 左旋数组中查找
- [答案V0.1版]精选微软等数据结构+算法面试100题 [前20题]
- 微软等数据结构+算法面试100题全部答案集锦
- [最新答案V0.3版]微软等数据结构+算法面试100题[第21-40题答案]
- [整理III]微软等数据结构+算法面试100题[最新第61-80题]
- 珍藏版、微软等数据结构+算法面试100题全部出炉
- 互联网--评微软等公司数据结构和算法面试100题 .
- [最新答案V0.4版]微软等数据结构+算法面试100题[第41-60题答案]
- 微软等数据结构+算法面试100题004
- 微软等数据结构+算法面试100题解答018
- 微软等数据结构+算法面试100题(2)--给出一个函数来输出一个字符串的所有排列