#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. COGS 182. [USACO Jan07] 均衡队形

    ★★   输入文件:lineup.in   输出文件:lineup.out   简单对比时间限制:4 s   内存限制:128 MB 题目描述 农夫约翰的 N (1 ≤ N ≤ 50,000) 头奶牛 ...

  2. Wampserver由橙变绿的解决过程

    因为C盘的内存问题,就重装了win7系统,那么就面临着很对软件要重新进行安装,安装wampserver时,再次遇到了服务器的图标一直是橙色的而不变绿色,安装包地址: http://download.c ...

  3. leetcode:查找

    1.  word ladder 题目: Given two words (start and end), and a dictionary, find the length of shortest t ...

  4. 816 Ambiguous Coordinates (many cases problem)

    https://www.cnblogs.com/Java3y/p/8846955.html -- link of the problem 816 IDEA: check the dot and int ...

  5. mybatis怎样自动生成java类,配置文件?

    其实没有什么东西是可以自动生成的,只不过是别人已经写好了,你调用罢了. 所以想要mybatis自动生成java类,配置文件等,就必须要一些配置和一些jar包.当然这些配置也很简单. 为了有个初步的认识 ...

  6. now()与sysdate()的区别(1)

        now()与sysdate()两个函数都以'YYYY-MM-DD HH:MM:SS'的形式表示表示当前的时间.比如: root@rac1 21:13:10> select sysdate ...

  7. vsftpd 启动 vsftpd:500 OOPS: bad bool value in config file for: guest_enable

    不然启动时会涌现毛病,举个例子 guest_enable=YES  后面出现空格,就会出现 为 vsftpd 启动 vsftpd:500 OOPS: bad bool value in config ...

  8. PHP APC安装与使用

    先要解决一下httpd-devel依赖库问题 yum install cyrus-sasl-devel db4-devel openldap apr apr-util apr-util-devel p ...

  9. 2017.11.24 算法分析与设计------Gay格雷码

    1. 格雷码问题: 对于给定的正整数n,格雷码为满足如下条件的一个编码序列: (1) 序列由2n个编码组成,每个编码都是长度为n的二进制位串. (2) 序列中无相同的编码. (3) 序列中位置相邻的两 ...

  10. Thymeleaf模板引擎绕过浏览器缓存加载静态资源js,css文件

    浏览器会缓存相同文件名的css样式表或者javascript文件.这给我们调试带来了障碍,好多时候修改的代码不能在浏览器正确显示. 静态常见的加载代码如下: <link rel="st ...