纪念逝去的岁月——C/C++快速排序
快速排序
代码
#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++快速排序的更多相关文章
- 纪念逝去的岁月——C++实现一个队列(使用类模板)
1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...
- 纪念逝去的岁月——C++实现一个栈(使用类模板)
这个版本是上个版本的加强版,上个版本的代码:http://www.cnblogs.com/fengbohello/p/4542912.html 目录 1.代码 2.运行结果 1.代码 1.1 调试信息 ...
- 纪念逝去的岁月——C++实现一个栈
1.代码 2.运行结果 1.代码 stack.cpp #include <stdio.h> #include <string.h> class ClsStack { priva ...
- 纪念逝去的岁月——C/C++排序二叉树
1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...
- 纪念逝去的岁月——C/C++二分查找
代码 #include <stdio.h> int binarySearch(int iList[], int iNum, int iX, int * pPos) { if(NULL == ...
- 纪念逝去的岁月——C/C++交换排序
交换排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
- 纪念逝去的岁月——C/C++选择排序
选择排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
- 纪念逝去的岁月——C/C++冒泡排序
冒泡排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
- 纪念逝去的岁月——C/C++字符串回文
判断字符串是否是回文: 1. 输入:hello world dlrow olleh 输出:1 2. 输入:nihao hello 输出:0 代码 #include <stdio.h> #i ...
随机推荐
- easyui tree折叠
标签 <div id="buildDiv" data-options="region:'center'" title="楼栋权限" s ...
- hdu 5833 Zhu and 772002 高斯消元
Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...
- 【MongoDB】2.可视化工具的安装和使用
首先:关于 能支持MongoDB新版本的可视化工具,争议不断,各人都有各人的支持. 因此之前选择安装的时候就安装了MongoDB 3.0.14版本的. 最终,确定使用Robomongo作为我第一个 ...
- 【POI word】使用POI实现对Word的读取以及生成
项目结构如下: 那第一部分:先是读取Word文档 package com.it.WordTest; import java.io.FileInputStream; import java.io.Fil ...
- js整理1
数组 比较时的隐式转化 var a = [1,2,3]; var b = [1,2,3]; a == b; //false a == '1,2,3'; //true; // var c = []; B ...
- express-16 与生产相关的问题2
处理未捕获的异常 在Node的异步世界中,未捕获的异常是特别需要关注的问题 app.get('/fail', function(req, res){ throw new Error('Nope!'); ...
- 09_IO流
1. IO(Input Output)流 IO流用来处理设备之间的数据传输 Java对数据的操作时通过流的方式 Java用于操作流的对象都在IO包中 流按操作数据分为两种: 字节流和字符流 流按类型分 ...
- 从Sql server 2008获取表字段属性信息,注释信息
select b.[value] from sys.columns a left join sys.extended_properties b on a.object_id=b.major_id ...
- Apache ActiveMQの版本更迭和Apache ActiveMQの故障转移
本文描述apache activemq 版本更迭的原因以及Apache ActiveMQのThe Failover Transport new features in 5.2.0 1.对信息的传输/ ...
- ural 1142. Relations
1142. Relations Time limit: 1.0 secondMemory limit: 64 MB Background Consider a specific set of comp ...