快速排序

代码

#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. Installing Hadoop on Mac OSX Yosemite Tutorial Part 1.

    Installing Hadoop on Mac OSX Yosemite Tutorial Part 1. September 23, 2014 Marek 68 Comments Install ...

  2. golang json 包简单分析

    首先上代码: func main() { b := true a1, _ := json.Marshal(b) a2, _ := Marshal(b) fmt.Println(string(a1)) ...

  3. wp8 入门到精通 Utilities类 本地存储+异步

    public class CCSetting { public async static void AddOrUpdateValue<T>(string key, T value) { t ...

  4. wp8 入门到精通 仿QQPivot 提示数量

    <Grid x:Name="LayoutRoot" Background="White"> <Grid Width="480&quo ...

  5. C# 创建Windows Service

    当我们需要一个程序长期运行,但是不需要界面显示时可以考虑使用Windows Service来实现.这篇博客将简单介绍一下如何创建一个Windows Service,安装/卸载Windows Servi ...

  6. 4.0 和4.5 app 和generic,xaml的问题

    4.0里面不支持Generic.xaml里面 <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=& ...

  7. loj 1002(spfa变形)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25828 题意:求所有点到给定的目标顶点的路径上的权值的最大值的最小 ...

  8. LaTex学习笔记(一)

    1. 语法 命令 普通命令 环境 数据 注释 2. 物理结构 导言 指定文档类型,引入宏包,定义命令,环境等 \documentclass[options]{class} \usepackage[op ...

  9. Liferay 6.2 改造系列之二:清理不需要的Portlet

    一.特殊Portlet: 以下Portlet数据特殊用途的Portlet,去除后会出现运行错误: 1.站点模版 通过com.liferay.portal.events.AddDefaultLayout ...

  10. hdu1003 dp

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003 #include<cstdio> #include<algorit ...