快速排序

代码

#include <stdio.h>

void printList(int iList[], int iLen)
{
int i = ;
for(i = ; i < iLen; i++)
{
printf("%d ", iList[i]);
}
printf("\n");
} void printList(int iList[], int iBegin, int iEnd)
{
int i = ;
for(i = ; i < iBegin; i++)
{
printf("%c ", '_');
}
for(i = iBegin; i < iEnd; i++)
{
printf("%d ", iList[i]);
}
printf("\n");
} int _quickSort(int iList[], int iLeft, int iRight)
{
if(iLeft >= iRight)
{
return ;
}
int i = iLeft, j = iRight;
int t = iList[i];
printf("%d<->%d mid(%d) : ", i, j, t);
while(i < j)
{
while(t < iList[j] && j > i)
{
j--;
}
if(j > i)
{
iList[i] = iList[j];
i++;
} while(t >= iList[i] && i < j)
{
i++;
}
if(i < j)
{
iList[j] = iList[i];
j--;
}
}
iList[i] = t;
printList(iList, );
_quickSort(iList, iLeft, i - );
_quickSort(iList, i + , iRight); return ;
} int Quick(int iList[], int iLen)
{
_quickSort(iList, , iLen - );
return ;
} int main()
{
int iNum = ;
int iList[] = {, , , , , , , , , };
printf("src : ");
printList(iList, iNum);
putchar('\n');
Quick(iList, iNum);
putchar('\n');
printf("dst : ");
printList(iList, iNum); return ;
}

编译

$ g++ -g -o quickSort quickSort.cpp

运行

$ ./quickSort
src : <-> mid() :
<-> mid() :
<-> mid() :
<-> mid() :
<-> mid() :
<-> mid() : dst :

再见……

纪念逝去的岁月——C/C++快速排序的更多相关文章

  1. 纪念逝去的岁月——C++实现一个队列(使用类模板)

    1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...

  2. 纪念逝去的岁月——C++实现一个栈(使用类模板)

    这个版本是上个版本的加强版,上个版本的代码:http://www.cnblogs.com/fengbohello/p/4542912.html 目录 1.代码 2.运行结果 1.代码 1.1 调试信息 ...

  3. 纪念逝去的岁月——C++实现一个栈

    1.代码 2.运行结果 1.代码 stack.cpp #include <stdio.h> #include <string.h> class ClsStack { priva ...

  4. 纪念逝去的岁月——C/C++排序二叉树

    1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...

  5. 纪念逝去的岁月——C/C++二分查找

    代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...

  6. 纪念逝去的岁月——C/C++交换排序

    交换排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

  7. 纪念逝去的岁月——C/C++选择排序

    选择排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

  8. 纪念逝去的岁月——C/C++冒泡排序

    冒泡排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...

  9. 纪念逝去的岁月——C/C++字符串回文

    判断字符串是否是回文: 1. 输入:hello world dlrow olleh 输出:1 2. 输入:nihao hello 输出:0 代码 #include <stdio.h> #i ...

随机推荐

  1. AOJ673 聪明的输入法(字典树)

    #include<cstdio> #include <cstdlib> #include <cstring> #include <iostream> # ...

  2. oracle sql rank dense_rank row_number fisrt last

    測試表emp

  3. 单图上传预览(uploadpreview )

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. hdu 1851 尼姆+巴什博弈

    先在每堆中进行巴什博弈,然后尼姆 #include<stdio.h> int main() { int T; int i,n; int ans,m,l; scanf("%d&qu ...

  5. hdu 4389 数位dp

    求区间内满足x%fx==0的数的个数,fx为该数各个位数上的数字之和Sample Input21 1011 20 Sample OutputCase 1: 10Case 2: 3 大小不是你想开,想开 ...

  6. Fragment 操作原理

      fragment 本质 fragment 本质上是 view 的容器和控制器,fragment 是 activity 的碎片. activity 是什么呢?activity 是四大组件之一,因为 ...

  7. C#写Windows Service(windows服务程序)

    背景:        要学习使用一个新东西,我们必须知道他是个什么东西.对于我们此次研究的windows服务来说,他又是个什么东西,其实也没有什么高深的了. windows service概述: 一个 ...

  8. felx项目属性(二)

    order flex-grow flex-shrink flex-basis flex align-self 1.1 order css order属性规定了弹性容器中的可伸缩项目在布局时的顺序.元素 ...

  9. DOM--3 DOM核心和DOM2 HTML(3)

    核心Element对象 操作Element对象的属性 为了简化对attributes的处理,Element对象中包含了很多用来操纵Node对象的attributes属性的方法: getAttribut ...

  10. 移动网页 -- CSS布局

    1.多栏结构 column-count column-width column:120px 3: column-gap:2em: column-rule:2px dotted gray: 跨越以及打断 ...