快速排序
来源:互联网 发布:sublime 格式化js css 编辑:程序博客网 时间:2024/05/20 09:43
#include<iostream>#include<algorithm>using namespace std;int partition(int A[], int left, int right) {int m = left + (right - left) / 2;if (A[left] > A[right])swap(A[left], A[right]);if (A[m] > A[right])swap(A[m], A[right]);if (A[m] > A[left])swap(A[m], A[left]);int temp = A[left];while (left<right){while (left<right&&A[right] > temp)--right;A[left] = A[right];while (left < right&&A[left] <= temp)++left;A[right] = A[left];}A[left] = temp;return left;}void quicksort(int A[], int left, int right) {if (left < right) {int mid = partition(A, left, right);quicksort(A, left, mid - 1);quicksort(A, mid + 1, right);}}int main() {int num[100] = { 23,34,5,7,5,24,7,13,7,68,954,4,51,9 };quicksort(num,0, 15);return 0;}
阅读全文
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- JS小游戏2048
- [转]利用OpenCV实现图像的叠加
- Android-25种开源炫酷动画框架
- equals()方法总结
- 【bzoj1190】[HNOI2007]梦幻岛宝珠 分层背包dp
- 快速排序
- 剑指 03-—链表从尾到头打印
- 【LeetCode】C# 80、Remove Duplicates from Sorted Array II
- Android自定义对话框
- phpstorm 2017激活
- centos 打开配置文件出错:E325: ATTENTION Found a swap file by the name "/etc/vsftpd/.vsftpd.conf.swp"
- Spring RestTemplate作为负载平衡器客户端
- ABAP 动态生成内表的几种方法(Several Methods of Dynamic Internal Table Creation)
- 虚拟数字货币开发小专家薪捷讲述,关于虚拟数字货币之王比特币论文区块链挖矿原理的那些事儿