//简单的选择排序算法:
// SelectSort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
int a[] = {78,69,23,54,56};
#define COUNT sizeof(a)/sizeof(a[0])
int i = 0;
int nMin;
while(i < COUNT)
{
int j = i+1;
nMin = i;
while(j < COUNT)
{
if(a[nMin] > a[j])
nMin = j;
++j;
}
if(nMin != i)
{
int t = a[nMin];
a[nMin] = a[i];
a[i] = t;
}
++i;
}
return 0;
}
选择排序算法
最新推荐文章于 2022-01-28 19:24:50 发布