快速排序2
来源:互联网 发布:mac osx 切换root 编辑:程序博客网 时间:2024/06/04 20:05
#include <iostream>using namespace std;const int N = 10;int data[]= {6,1,2,7,9,3,4,5,10,8};void quickSort(int* data, int low,int high);void printArray(int* data, int n);int partition(int* data,int low, int high);int main(){ quickSort(data,0,N-1); printArray(data,N); return 0;}void quickSort(int* data, int low, int high){ if(low>=high) return; int key = partition(data,low,high); quickSort(data,low,key-1); quickSort(data,key+1,high);}void printArray(int* data, int n){ for(int i=0;i<n;++i) { cout<<data[i]<<"\t"; } cout<<endl;}int partition(int* data,int l, int h){ int low=l,high=h; int temp = data[low]; while(low<high) { while(low<high && data[high]>=temp) --high; while(low<high && data[low]<=temp) ++low; if(low<high) { data[low] ^= data[high]; data[high] ^= data[low]; data[low] ^= data[high]; } } data[l] = data[low]; data[low] = temp; return low;}
0 0
- 排序2-快速排序
- 排序算法2---快速排序
- 排序(2)快速排序
- 快速排序2
- 快速排序2
- 快速排序2
- 快速排序算法2
- 快速排序(2)
- 快速排序2 随机化
- 快速排序2
- 快速排序2
- 23 快速排序2
- 快速排序2
- 7.3.2 快速排序
- 快速排序2
- 快速排序2
- 排序算法2-快速排序、归并排序
- 排序 - 交换排序 [2 -- 快速排序]
- NYOJ 27 水池数目(深搜)
- redis学习笔记(18)---事件
- Leetcode 237. Delete Node in a Linked List
- gdb 调试利器
- Tableau Desktop简单介绍
- 快速排序2
- 常量和变量
- matlab 二进制文件的读取fead,节约内存
- Python的GIL是什么鬼,多线程性能究竟如何
- hdu2544 最短路
- 51单片机定时器精度问题之一
- Unity3D 性能优化
- 【Qt】自定义样式之QSS
- LeetCode Two Sum