您的位置:首页 > 其它

[Sort]选择排序

2015-11-29 10:11 295 查看
详细介绍,在本博客的数据结构栏目里有,不过是java版

#include<iostream>

using namespace std;

void Select_Sort(int a[],int num)
{
for(int i=0;i<num-1;i++)
{
int x = i; //要选择的点的位置
for(int j = i+1;j<num;j++)
{
if(a[x] > a[j])
{
//说明j更小
x = j;
}
}
if(x != i)
{
int temp = a[i];
a[i] = a[x];
a[x] = temp;
}
}
}

void main()
{
int a[] = {57,68,59,52,72,28,96,33,24};
int count = sizeof(a) / sizeof(a[0]);
Select_Sort(a,count);
for(int i=0;i<count;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: