/*
*Copyright (c) 2014,烟台大学计算机与控制工程学院
*All rights reserved
*版本号:v1.0
*作者:范星月
*完成日期:2014年12月9号
*
*问题描述:两种排序法的运用
*问题输入:输入数组
*问题输出:由小到大的顺序输出
*/
#include <iostream>
using namespace std;
int main()
{
int a[10],i,j,t;
cout <<"please input 10 numbers "<<endl ;
for (i=0;i<10;i++)
cin>>a[i];
for (j=0;j<10;j++)
for (i=0;i<9-j;i++)
if (a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
for (i=0;i<10;i++)
cout <<a[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
void select_sort (int array[] ,int n);
int main()
{
int a[10],i;
for (i=0; i<10; i++)
cin>>a[i];
cout <<endl;
select_sort (a,10);
for (i=0; i<10; i++)
cout <<a[i]<<" ";
}
void select_sort (int array[],int n)
{
int i,j,k,t;
for(i=0; i<n-1; i++)
{
k=i;
for (j=i+1; j<n; j++)
if (array [j]<array [k])
k=j;
t=array [k];
array [k]=array[i];
array[i]=t;
}
}
<img src="https://img-blog.csdn.net/20141210160941086?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTcxNjEyMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<img src="https://img-blog.csdn.net/20141210161204718?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTcxNjEyMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
学习总结:冒泡法和选择法,用数组名作函数参数
学习心得:加油