纪念逝去的岁月——C/C++冒泡排序
冒泡排序
代码
#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++冒泡排序的更多相关文章
- 纪念逝去的岁月——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 ...
随机推荐
- SQL常用方言列表
DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS390 org.hi ...
- 兼容所有浏览器的JS动态显示当前日期时间
<script type="text/javascript"> function show_cur_times(){ //获取当前日期 var date_time = ...
- HR外包系统 - 账款
01 账款-服务费,注意多币种以及收款对象和联系人的设置 02 代收代付,注意多币种以及收款对象和联系人的设置 03 账单要保存服务费计算的整个过程,便于后面出报表和数据分析 04 出报表时,要考虑 ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- HDU 5807 Keep In Touch DP
Keep In Touch Problem Description There are n cities numbered with successive integers from 1 to n ...
- Servlet获取类路径下的资源
示例程序: package cn.yzu; import java.io.IOException; import java.io.InputStream; import javax.servlet.S ...
- 一张图入门python
- 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 ...
- hdu1003 dp
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003 #include<cstdio> #include<algorit ...
- RedHat5.1下安装Seismic Unix44R1
以前安装过好几次,在这里总结下.不足之处,欢迎批评指正. 用su44用户登录,修改环境变量(~/.bash_profile文件中添加) export CWPROOT=/home/`whoami`/cw ...