Random_QuickSort
来源:互联网 发布:ubuntu 软件安装 编辑:程序博客网 时间:2024/05/19 15:19
#include "stdafx.h"int PARTITION(int a[], int p, int r) //以递增顺序排序{ int x = a[r]; int i = p - 1; for (int j = p; j < r; ++j) { if (a[j] < x) { ++i; int temp = a[i]; a[i] = a[j]; a[j] = temp; } } int temp = a[i + 1]; a[i + 1] = a[r]; a[r] = temp; return i + 1;}int Random_Partition(int a[], int p, int r){ srand(time(NULL)); //以当前时间作为种子,以便每次产生的随机数不同 int i = rand() % (r - p) + p; //产生随机数 int temp = a[i]; a[i] = a[r]; a[r] = temp; return PARTITION(a, p, r);}void Random_QuickSort(int a[], int p, int r){ if (p < r) { int q = Random_Partition(a, p, r); Random_QuickSort(a, p, q - 1); Random_QuickSort(a, q + 1, r); }}int _tmain(int argc, _TCHAR* argv[]){ int a[] = { 3, 1, 7, 5, 9, 4, 12, 0 }; int len = sizeof(a) / 4 - 1; Random_QuickSort(a, 0, len); for (int i = 0; i < len + 1; ++i) { cout << a[i] << endl; } return 0;}
0 0
- Random_QuickSort
- PLSQL Developer使用技巧整理
- pip缓存下载的包文件
- 在Windows中安装 HTCondor
- nyoj 618 追击【理解题意】
- 学习GitHub的第一周笔记
- Random_QuickSort
- itext 生成PDF文档后,iphone显示乱码,我是这样解决的。
- 文件解压缩
- PLSQL DEVELOPER 使用的一些技巧【转】
- 一对多关系修改为多对多关系
- Android Studio多渠道打包和代码混淆教程
- Spring HandlerInterceptor的使用
- OpenMP
- java compiler level does not match the version of the installed java project facet 解决方法