冒泡排序

代码

#include <stdio.h>

void printList(int iList[], int iLen)
{
int i = ;
for(i = ; i < iLen; i++)
{
printf("%d ", iList[i]);
}
printf("\n");
} int bubbleSort(int iList[], int iLen)
{
int i = , j = ;
for(i = ; i < iLen - ; i++)
{
for(j = ; j < iLen - i - ; j++)
{
if(iList[j] <= iList[j + ])
{
continue;
}
int iTemp = iList[j];
iList[j] = iList[j + ];
iList[j + ] = iTemp;
}
printf("%d : ", i);
printList(iList, iLen);
} return ;
} int main(int argc, char * argv[])
{
int iList[] = {, , , , , , , , , };
printf("src : ");
printList(iList, );
putchar('\n');
bubbleSort(iList, );
putchar('\n');
printf("dst : ");
printList(iList, ); return ;
}

编译

$ g++ -o bubbleSort bubbleSort.cpp

运行

$ ./bubbleSort
src : : 9
:
:
:
:
:
:
:
: 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. SQL常用方言列表

    DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS390 org.hi ...

  2. 兼容所有浏览器的JS动态显示当前日期时间

    <script type="text/javascript"> function show_cur_times(){ //获取当前日期 var date_time = ...

  3. HR外包系统 - 账款

    01 账款-服务费,注意多币种以及收款对象和联系人的设置 02 代收代付,注意多币种以及收款对象和联系人的设置 03 账单要保存服务费计算的整个过程,便于后面出报表和数据分析 04 出报表时,要考虑 ...

  4. HDU 5919 Sequence II 主席树

    Sequence II Problem Description   Mr. Frog has an integer sequence of length n, which can be denoted ...

  5. HDU 5807 Keep In Touch DP

    Keep In Touch Problem Description   There are n cities numbered with successive integers from 1 to n ...

  6. Servlet获取类路径下的资源

    示例程序: package cn.yzu; import java.io.IOException; import java.io.InputStream; import javax.servlet.S ...

  7. 一张图入门python

  8. sudo -u hdfs hdfs balancer出现异常 No lease on /system/balancer.id

    16/06/02 20:34:05 INFO balancer.Balancer: namenodes = [hdfs://dlhtHadoop101:8022, hdfs://dlhtHadoop1 ...

  9. hdu1003 dp

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

  10. RedHat5.1下安装Seismic Unix44R1

    以前安装过好几次,在这里总结下.不足之处,欢迎批评指正. 用su44用户登录,修改环境变量(~/.bash_profile文件中添加) export CWPROOT=/home/`whoami`/cw ...