冒泡排序

代码

#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. 深入剖析iLBC的丢包补偿技术(PLC)

    转自:http://blog.csdn.net/wanggp_2007/article/details/5136609 丢包补偿技术(Packet Loss Concealment——PLC)是iLB ...

  2. AxureRP7.0各类交互效果汇总帖(转)

    了便于大家参考,我把这段时间发布分享的所有关于AxureRP7.0的原型做了整理. 以下资源均有对应的RP源文件可以下载. 当然 ,其中有部分是需要通过完成解密游戏[攻略]才能得到下载地址或者下载密码 ...

  3. JMeter中的关联-正则表达式提取(2)

    JMeter获取正则表达式中的提取的所有关联值的解决方法: 需求如下: { : ", : "results": : [ : : { : : : "total_e ...

  4. 自定义ActionBar

    /** * 1.创建ActionBar对象getSupportActionBar() * 2.布置自己的ActionBar布局(在res/layout) * 3.把自定义的ActionBar布局加载到 ...

  5. ajax调用WebServices服务方法和传参调用WebServices注意事项

    先演示下ajax是如何调用WebServices中的方法    1.新建一个页面default.aspx,一个Web服务    在页面中引用jQuery文件. <script src=" ...

  6. javascript写在<head>和<body>里的区别

    Javascript写在哪里?概括起来就是三种形式:1. 内部:Html网页的<body></body>中:2. 内部:Html网页的<head></head ...

  7. SpringJDBC解析2-execute方法

    大家都使用过JDBCTEMPLATE的execute方法,execute作为数据库操作的核心入口,将大多数数据库操作相同的步骤统一封装,而将个性化的操作使用参数PreparedStatementCal ...

  8. DSP using MATLAB 示例Example3.4

    代码: n = [-1:3]; x = [1:5]; % x(n) = {1,2,3,4,5} % * % k = 0:500; w = (pi/500)*k; % [0,pi] axis divid ...

  9. Smart原则

    遵循smart原则,必须是具体的.可衡量的.可达到的.与岗位职责相关的.有明确达成期限的.

  10. CentOS下vm虚拟机桥接联网

    CentOS下vm虚拟机桥接联网   vm虚拟机下的桥接联网相当于虚拟机是一个独立的主机,直接与外网相连,这是比较好的连接方式,这样外网的机子就可以直接访问到虚拟机了.   首先虚拟机的联网方式设置为 ...