quick sort去除无用判断
#include <stdio.h>
#include <stdlib.h> //int a[]={1000,10000,9,10,30,20,50,23,90,100,10};
int a[]={,,,,,}; int length=sizeof(a)/sizeof(int); int swap(int start, int stop){
int temp;
temp=a[start];
a[start]=a[stop];
a[stop]=temp;
return ;
} int quicksort(int start, int stop) { int i; int ostart=start;
int ostop=stop; int k=a[start];
int middle;
if(start >= stop){
return ;
} while( start < stop ){ //printf("\n begin start=%d,stop=%d ,k=%d , ostart=%d,ostop=%d\n" , start, stop, k,ostart,ostop);while((a[stop] >= k) &&(start<stop)){
stop--;
} while( (a[start] < k) &&(start<stop)){
start++;
}
//printf("after move start=%d,stop=%d ,k=%d , ostart=%d,ostop=%d\n" , start, stop, k,ostart,ostop);
if( start < stop ){
swap(start,stop);
}
//printf("may after swap start=%d,stop=%d ,k=%d , ostart=%d,ostop=%d\n" , start, stop, k,ostart,ostop); }
quicksort(ostart, start);
quicksort(start+, ostop); } int main(){ printf("length= %d\n",length);
int i;
printf("\n");
quicksort(,length-);
printf("\n\n\n");
for(i=;i<length;i++){
printf("%d\n" , a[i]);
}
printf("\n"); return ;
}
quick sort去除无用判断的更多相关文章
- pat1101. Quick Sort (25)
1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a ...
- [算法]——快速排序(Quick Sort)
顾名思义,快速排序(quick sort)速度十分快,时间复杂度为O(nlogn).虽然从此角度讲,也有很多排序算法如归并排序.堆排序甚至希尔排序等,都能达到如此快速,但是快速排序使用更加广泛,以至于 ...
- quick sort 的简化实现
Pivot 随机选取意义不大 第一种方法使用随机pivot,使得尽可能平均二分序列,而实际上一般来说需要排序的集合往往是乱序的,无需重新生成随机数作为pivot,大可使用固定位置的数作为pivot,这 ...
- 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- [算法] 快速排序 Quick Sort
快速排序(Quick Sort)使用分治法策略. 它的基本思想是:选择一个基准数,通过一趟排序将要排序的数据分割成独立的两部分:其中一部分的所有数据都比另外一部分的所有数据都要小.然后,再按此方法对这 ...
- 基础排序算法之快速排序(Quick Sort)
快速排序(Quick Sort)同样是使用了分治法的思想,相比于其他的排序方法,它所用到的空间更少,因为其可以实现原地排序.同时如果随机选取中心枢(pivot),它也是一个随机算法.最重要的是,快速排 ...
- 快速排序(Quick Sort)的C语言实现
快速排序(Quick Sort)的基本思想是通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对着两部分记录继续进行排序,以达到整个序列有序,具体步骤 ...
- Quick Sort In-place Implementation
在线运行PHP http://www.compileonline.com/execute_php_online.php <?php function swap( &$a, &$b ...
- 快速排序(Quick Sort)
快速排序是初学者比较难理解的几个算法之一,这里尽可简单化地讲解,希望能帮到大家. 快速排序基本步骤: 从数列中挑出一个元素,称为"基准"(pivot). 重新排序数列,所有元素比基 ...
随机推荐
- C#学习基础,面向对象的三大特征
学习C#编程,相信大家除了经常接触的是hello world之外,更多的是进一步的去熟悉这门语言的基本特征,以及有哪些概念是我们必要掌握了解的,相信大家都是会知道面向对象的三大特性分别是:封装,继承, ...
- failed: No module named 'catkin_pkg' Make sure that you have installed "catkin_pkg"
https://stackoverflow.com/questions/43024337/why-this-error-when-i-try-to-create-workspaces-in-ros# ...
- 了解iOS上的可执行文件和Mach-O格式
http://www.cocoachina.com/mac/20150122/10988.html http://www.reinterpretcast.com/hello-world-mach-o ...
- 【[SDOI2017]新生舞会】
题目 好题啊 我们要求的是 \[C=\frac{\sum_{i=1}^na_i}{\sum_{i=1}^nb_i}\] 使得\(C\)最大 显然 \[C\times \sum_{i=1}^nb_i=\ ...
- DOM(四):h5扩展方法
getElementByClassName()方法getElementByClassName()方法接收一个参数,即一个包含一或多个类名的字符串,返回带有指定类的所有元素的NodeList //取得所 ...
- [ difflib] simple1.py
#!/usr/bin/env python # _*_ coding:utf-8 _*_ import difflib text1 = """text1: # 定义字符串 ...
- 剑指offer25 二叉树中和为某一直的路径
先序遍历 class Solution { public: vector<vector<int> > FindPath(TreeNode* root,int expectNum ...
- 通过ODBC接口访问人大金仓数据库
国产化软件和国产化芯片的窘境一样,一方面市场已经存在性能优越的同类软件,成本很低,但小众的国产化软件不仅需要高价买入版权,并且软件开发维护成本高:另一方面,国产软件目前普遍难用,性能不稳定,Bug ...
- 移除input number上的spinner
HTML 5 的表单中有着丰富的input种类,比如说input[type="number"],就可以保证用户输入数字,但是input也有一些不好的地方——带有 spinner. ...
- python——文件处理
1.文件处理 f = open(file="file01.txt", mode="r", encoding="utf-8") #python ...