Quick_sort
typedef int ElementType; void Quick_sort(ElementType A[], int N)
{
Quicksort(A, , N-);
} void Quicksort(ElementType A[], int left, int right)
{
if(right-left+ < )
{
//插入排序
Insert_sort(A, right-left+);
}
else
{
//调用快排
//找中位数,优化快排
pivot = Median3(A, left, right); int i = left;
int j = right; while(true)
{
while(A[++i] < pivot);
while(A[--j] > pivot);
if(i < j)
swap(&A[i], &A[j]);
else
break;
}
swap(&A[i], &A[right-]); //递归左右
Quicksort(A, left, i-);
Quicksort(A, i+, right);
}
} void Insert_sort(ElementType A[], int N)
{
for(int i = ; i < N; i++)
{
int j;
int Temp = A[i];
for(j = i-; j >= && A[j] > Temp; j--)
{
A[j] = A[j+];
}
A[j] = Temp;
}
}
Quick_sort的更多相关文章
- 快速排序quick_sort(python的两种实现方式)
排序算法有很多,目前最好的是quick_sort:unstable,spatial complexity is nlogN. 快速排序原理 python实现 严蔚敏的 datastruct书中有伪代码 ...
- python数据结构之quick_sort
Quick sort , also known as partition-exchange sort, divides the data to be sorted into two separate ...
- 快速排序(c++,递归)quick_sort
放上c++代码,模板 1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 5 in ...
- 快速排序Quick_Sort
快排——排序中的明星算法,也几乎是必须掌握的算法,这次我们来领略以下快排为何魅力如此之大. 快排主要有两种思路,分别是挖坑法和交换法,这里我们以挖坑法为例来进行介绍,交换法可以参考这篇博文.值得一提的 ...
- 如何进行python性能分析?
在分析python代码性能瓶颈,但又不想修改源代码的时候,ipython shell以及第三方库提供了很多扩展工具,可以不用在代码里面加上统计性能的装饰器,也能很方便直观的分析代码性能.下面以我自己实 ...
- [算法]——快速排序(Quick Sort)
顾名思义,快速排序(quick sort)速度十分快,时间复杂度为O(nlogn).虽然从此角度讲,也有很多排序算法如归并排序.堆排序甚至希尔排序等,都能达到如此快速,但是快速排序使用更加广泛,以至于 ...
- php排序算法
<?php//冒泡排序(数组排序) function bubble_sort($array){ $count = count($array); if ($count <= 0) retur ...
- 不重新编译php安装配置eAccelerator
eAccelerator属于一个免费的开源php加速.优化.编译和动态缓存项目,原理和apc类似,都是通过缓存php编译后的opcode代码来提高php脚本的执行性能,而且eAccelerator本身 ...
- php冒泡排序和快速排序
如有错误,请指出... //快速排序(array_merge整合数组)function quick_sort($arr){ $num=count($arr); if($num<=1){ retu ...
随机推荐
- Unity3d项目入门之Rolling Ball
下面通过分析制作一个简单的收集特定物体的滚球游戏来入门unity,包括操作面板和C#脚本的编写导入,创建Game Object和给Object添加组件等等. 一 初始设置 在Assert下创建主场景M ...
- 15. 3Sum (JAVA)
Given an array nums of n integers, are there elements a, b, cin nums such that a + b + c = 0? Find a ...
- Distance on the tree
Distance on the tree https://nanti.jisuanke.com/t/38229 DSM(Data Structure Master) once learned abou ...
- Python开发【第十篇】:Redis
缓存数据库介绍 NoSQL(Not Only SQL),即"不仅仅是SQL",泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应对web2.0网站,特别是 ...
- python添加post请求
1.进入python的安装目录下的Scripts目录 ,利用pip install requests安装第三方模块 2.火狐浏览器自带firebug,打开http://10.148.111.111/q ...
- How to decode input data from a contract transaction without ABI?
1 I've found some libraries which decode input from transaction, but all of them require ABI of cont ...
- pycrypto 安装 Crypto 报错 error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools&quo ...
- 视频剪辑软件原型-videocut
制作软件:墨刀 分享网址:<iframe src="https://modao.cc/app/fb0e31590711295ebebdf50fff7dd9861b7a9c1d/embe ...
- java之数据库相关
这篇还是在回顾知识.主要是关于java连接Sqlserver2012数据库的一些方式记录,以便以后查询. 十一之内复习完这些知识就可以新学Hibernate啦(*^▽^*) 1.普通方式 注意,在连接 ...
- 《笨方法学Python》加分题29
加分练习猜一猜 “if 语句” 是什么,他有什么作用.在做下一道题之前,试着用自己的话回答下面的问题: 你认为 if 对他下一行代码做了什么?为什么 if 语句的下一行需要 4 个空格缩进?如果不缩进 ...