选择排序

代码

#include <stdio.h>

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

编译

$ g++ -o selectSort selectSort.cpp

运行

$ ./selectSort
src : 0
0 dst :

再见……

纪念逝去的岁月——C/C++选择排序的更多相关文章

  1. 纪念逝去的岁月——C/C++排序二叉树

    1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...

  2. 纪念逝去的岁月——C++实现一个队列(使用类模板)

    1.代码 2.运行结果 1.代码 #include <stdio.h> #include <string.h> template <typename T> clas ...

  3. 纪念逝去的岁月——C++实现一个栈(使用类模板)

    这个版本是上个版本的加强版,上个版本的代码:http://www.cnblogs.com/fengbohello/p/4542912.html 目录 1.代码 2.运行结果 1.代码 1.1 调试信息 ...

  4. 纪念逝去的岁月——C++实现一个栈

    1.代码 2.运行结果 1.代码 stack.cpp #include <stdio.h> #include <string.h> class ClsStack { priva ...

  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. ASP.NET多线程下使用HttpContext.Current为null解决方案 2015-01-22 15:23 349人阅读 评论(0) 收藏

    问题一:多线程下获取文件绝对路径 当我们使用HttpContext.Current.Server.MapPath(strPath)获取绝对路径时HttpContext.Current为null,解决办 ...

  2. go sample - format

    go sample - format package mainimport "fmt"import "os"type point struct { x, y i ...

  3. servlet、genericservlet、httpservlet之间的区别

    转自:http://blog.csdn.net/rat9912345/article/details/5161789 当编写一个servlet时,必须直接或间接实现servlet接口,最可能实现的方法 ...

  4. JS 时间格式化

    Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month &quo ...

  5. VS2013安装oepncv2.4.10 以及opencv 3.0.0

    Author:Maddock Date:2014.12.27 …………………………………………………………………………………………………… PS: VS2013 + OPENCV 3.0.0 的安装, ...

  6. 仿IOS圆形下载进度条

    /** * Created by C058 on 2016/5/25. */ public class MyHoriztalProgressBar extends ProgressBar { priv ...

  7. HDU 3461 Code Lock(并查集)

    很好的一个题,思想特别6 题意:给你小写字母个数n,每个字母可以向上翻动,例如:d->c,a->z.然后给你m对数(L,R)(L<=R),表示[L,R]之间可以同时向上翻动,且翻动后 ...

  8. strcmp函数的使用

    Action() { /*********************************   * Author:旺仔   * object:strcmp   * date:2015-12-09    ...

  9. 51nod 1051 求最大子矩阵和

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1051 1051 最大子矩阵和 基准时间限制:2 秒 空间限制: ...

  10. css/js(工作中遇到的问题)

    移动设备点击时去掉外加的蓝色边框 a, input, button { -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-tap-highligh ...