#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去除无用判断的更多相关文章

  1. pat1101. Quick Sort (25)

    1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a ...

  2. [算法]——快速排序(Quick Sort)

    顾名思义,快速排序(quick sort)速度十分快,时间复杂度为O(nlogn).虽然从此角度讲,也有很多排序算法如归并排序.堆排序甚至希尔排序等,都能达到如此快速,但是快速排序使用更加广泛,以至于 ...

  3. quick sort 的简化实现

    Pivot 随机选取意义不大 第一种方法使用随机pivot,使得尽可能平均二分序列,而实际上一般来说需要排序的集合往往是乱序的,无需重新生成随机数作为pivot,大可使用固定位置的数作为pivot,这 ...

  4. 1101. Quick Sort (25)

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  5. [算法] 快速排序 Quick Sort

    快速排序(Quick Sort)使用分治法策略. 它的基本思想是:选择一个基准数,通过一趟排序将要排序的数据分割成独立的两部分:其中一部分的所有数据都比另外一部分的所有数据都要小.然后,再按此方法对这 ...

  6. 基础排序算法之快速排序(Quick Sort)

    快速排序(Quick Sort)同样是使用了分治法的思想,相比于其他的排序方法,它所用到的空间更少,因为其可以实现原地排序.同时如果随机选取中心枢(pivot),它也是一个随机算法.最重要的是,快速排 ...

  7. 快速排序(Quick Sort)的C语言实现

    快速排序(Quick Sort)的基本思想是通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对着两部分记录继续进行排序,以达到整个序列有序,具体步骤 ...

  8. Quick Sort In-place Implementation

    在线运行PHP http://www.compileonline.com/execute_php_online.php <?php function swap( &$a, &$b ...

  9. 快速排序(Quick Sort)

    快速排序是初学者比较难理解的几个算法之一,这里尽可简单化地讲解,希望能帮到大家. 快速排序基本步骤: 从数列中挑出一个元素,称为"基准"(pivot). 重新排序数列,所有元素比基 ...

随机推荐

  1. 笨办法学Python(三十一)

    习题 31: 作出决定 这本书的上半部分你打印了一些东西,而且调用了函数,不过一切都是直线式进行的.你的脚本从最上面一行开始,一路运行到结束,但其中并没有决定程序流向的分支点.现在你已经学了 if,  ...

  2. 数组:获取GET的键名

    1.今天仓鼠遇到这个情况:通过$_GET获取参数,但是参数变成了键名形式 2.那仓鼠想要拿到这个键名,那就要:使用array_keys()获取数组中的所有键名,然后进行转换 代码如下: 结果: 以上 ...

  3. 前端js限制上传文件类型及大小(1)

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. JSON对象与XML相互转换工具类

    依赖jar <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId ...

  5. MAC os x 系统java开发环境搭建教程

    https://jingyan.baidu.com/article/3d69c55147a3baf0cf02d7ca.html

  6. openstack cinder api对应的命令行接口

    a) Create Volume         cinder create 1 --display-name admin-volume1     cinder create --display-na ...

  7. C#使用ref和out传递数组

    C#使用ref和out传递数组 一.使用ref参数传递数组 数组类型的ref参数必须由调用方明确赋值.因此,接受方不需要明确赋值.接受方数组类型的ref参数能够修改调用方数组类型的结果.可以将接受方的 ...

  8. input的placeholder的颜色、字号、边距设置

    #scbar_txt::-webkit-input-placeholder { /* WebKit browsers */    text-indent: 10px; font-size:16px; ...

  9. 分布式系统session一致性问题

    一.引言 1.什么是session Session 是服务器用来保存用户操作的一系列会话信息,由Web容器进行管理.最常见的,会把用户的登录信息.用户信息存储在 session 中,以保持登录状态. ...

  10. singnal 13 was raised

    在app运行过程中按下home键或者其他原因app被挂起,socket连接不会断开,服务器为了节省资源,在一段时间后会主动关闭这个连接.当玩家再次切回到游戏后,前端并不知道这个连接已经断开了,继续通过 ...