练手代码(分治实现):

input:

int input[] = {12,6,3,9,10,6,2};

output:

=======================
len = 7
input[0]=2
input[1]=3
input[2]=6
input[3]=6
input[4]=9
input[5]=10
input[6]=12

这里强烈推荐一款web端代码编译网站,不用换个机器想写点code还必须安装编译器。

http://codepad.org/ 

界面如下:

int partition(int input[],int low,int high){
int pivot = input[low];
while(low < high){
  while(low < high && input[high] >= pivot) high--;
  input[low] = input[high];
   while(low < high && input[low] <= pivot) low++;
  input[high] = input[low];
}//low=high时跳出
input[low] = pivot;
return low;
} int quicksort(int input[],int inplen,int low,int high){//快速排序
int k=;
if(low < high){
k = partition(input,low,high);
quicksort(input,inplen,low,k-);
quicksort(input,inplen,k+,high);
}
return ;
} int main(){
printf("=======================\n");
int input[] = {,,,,,,};
int input1[] = {,,};
int len = sizeof(input)/sizeof(int);
printf("len = %d\n",len);
quicksort(input,len,,len-);
int i=;
for(;i<len;i++){
printf("input[%d]=%d\n",i,input[i]);
}
return ;
}

c语言:快速排序的更多相关文章

  1. C语言快速排序

    复习快速排序,用C语言实现: #include <stdio.h> int quicksort(int begin, int end, int a[], int len); void ma ...

  2. c语言 快速排序---归并排序----堆排序

    //快速排序: #include <stdio.h> #define MAX 500000 int s[MAX]; void Q_Sort(int start,int end) { int ...

  3. c语言 快速排序

    #include<stdio.h> #include<stdlib.h> #define BUF_SIZE 10 void display(int array[], int m ...

  4. c语言快速排序算法(转)

    原文链接http://blog.csdn.net/morewindows/article/details/6684558 快速排序由于排序效率在同为O(N*logN)的几种排序方法中效率较高,因此经常 ...

  5. C语言“快速排序”函数写法

    代码是:C语言中快速排的写法,要加入头文件   <stdlib.h> qsort(数组名, 长度, 数据类型大小,比较算子 ): #include <stdio.h> #inc ...

  6. C语言快速排序函数------qsort();

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> ty ...

  7. C语言排序

    排序算法 快速排序 C语言快速排序qsort(数组,长度,元素大小,cmp函数(*,*))//注意函数cmp的参数为指针 #include <stdio.h> #include <s ...

  8. C++程序设计(一)

    1. 函数指针 程序运行期间,每个函数都会占用一段连续的内存空间.而函数名就是该函数所占内存区域的起始地址(也称"入口地址").我们可以将函数的入口地址赋给一个指针变量,使该指针变 ...

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

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

  10. 深入浅出数据结构C语言版(20)——快速排序

    正如上一篇博文所说,今天我们来讨论一下所谓的"高级排序"--快速排序.首先声明,快速排序是一个典型而又"简单"的分治的递归算法. 递归的威力我们在介绍插入排序时 ...

随机推荐

  1. Cloudera CDH 5集群搭建(yum 方式)

    1      集群环境 主节点 master001 ~~ master006 从节点 slave001 ~~ slave064 2      安装CDH5的YUM源 rpm -Uvhhttp://ar ...

  2. MessageDigest简要

    本文博客原 參考文章:http://blog.sina.com.cn/s/blog_4f36423201000c1e.html 一.概述 java.security.MessageDigest类用于为 ...

  3. Unit Test Via Visual Studio

    转载Unit Test Via Visual Studio-Part1 写在开头:Coding ain't done until all the tests run. No unit test no ...

  4. Jquery()核心函数的7个重载方法

    (1) jquery() 该函数返回一个空的jQuery对象.在jQuery1.4以后的版本中,改函数返回一个空的jQuery对象.在之后的版本中,该函数会返回一个包含document节点的对象. ( ...

  5. [Elasticsearch] 分布式文件存储

    本文翻译自Elasticsearch官方指南的distributed document store一章. 分布式文档存储 在上一章中,我们一直在介绍索引数据和获取数据的方法.可是我们省略了非常多关于数 ...

  6. jQuery实现按键盘方向键翻页

    1.jQuery代码: $(document).ready(function(){ var prevpage=$("#pre").attr("href"); v ...

  7. POJ 2492 并查集应用的扩展

    A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28651 Accepted: 9331 Descri ...

  8. Installshield获取安装包版本的系统变量是IFX_PRODUCT_VERSION

    原文:Installshield获取安装包版本的系统变量是IFX_PRODUCT_VERSION Installshield获取安装包版本的系统变量为IFX_PRODUCT_VERSION 当笔记记下 ...

  9. Web Service单元测试工具实例介绍之SoapUI

    原文  Web Service单元测试工具实例介绍之SoapUI SoapUI是当前比较简单实用的开源Web Service测试工具,提供桌面应用程序和IDE插件程序两种使用方式.能够快速构建项目和组 ...

  10. 使用Python改写的身份证信息查询小程序

    花了几天时间过了一遍python基础.真心感觉python让世界充满了爱…先简单的使用一下python好了,拿以前写的<C语言身份证信息查询系统(修改版)>开刀~ 很多东西,不需要考虑C语 ...