博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
快速排序(基于算法导论思想)的C语言实现
阅读量:4341 次
发布时间:2019-06-07

本文共 775 字,大约阅读时间需要 2 分钟。

快速排序(算法导论版)

#include 
using namespace std;void swap(int &a,int &b){ int temp = a; a = b; b = temp;}int parttion(int a[],int l,int r){ int x = a[r]; //取数组最后一个元素为基准值 int i = l - 1; //比基准值小的数组的窗口数组最大下标 for(int j = l;j <= r-1;j++){ if(a[j] <= x){ i = i + 1; swap(a[i],a[j]); } } swap(a[i+1],a[r]); return i+1;}void quick_sort(int a[],int l,int r){ if(l < r){ int q = parttion(a,l,r); quick_sort(a,l,q-1); quick_sort(a,q,r); }}int main(void){ int a[8] = {2,8,7,1,3,5,6,4}; quick_sort(a,0,7); cout<<"排序后的值为:\n"; for(int i = 0;i < 8;i++){ printf("%d ",a[i]); } return 0;}

转载于:https://www.cnblogs.com/Western-Trail/p/10174614.html

你可能感兴趣的文章
pinyin4j新手教程
查看>>
tracert路由跟踪命令分析判断
查看>>
[bzoj1059] [ZJOI2007]矩阵游戏
查看>>
linux系统结构和系统命令初步
查看>>
各种框架实现了经典的 todo 应用
查看>>
Android Studio Tips Of the Day – Roundup
查看>>
CSS display:inline和float:left两者区别探讨
查看>>
前端可以用的资源
查看>>
【poj3070】 Fibonacci
查看>>
关于php的一些基础知识
查看>>
团队作业1——团队展示&博客作业查重系统
查看>>
hdu 3038 How Many Answers Are Wrong (带权并查集)
查看>>
Here is the title.
查看>>
serv_u提权方法总结
查看>>
字符串相互转字符数组 string byte 数组 array of byte
查看>>
进程,线程,携程复习
查看>>
第九次作业
查看>>
十大排序代码实现(python)
查看>>
[转载]什么是对象序列化,为什么要使用
查看>>
邮政编码联动地址
查看>>