/*
对输入数组ary按从小到大排序,n为数组大小
*/
void CSort::my_sort1(int *ary,int n)
{
int ct,selt,tp;
for(int i=0;i<n;i++)
{
selt=ary[0];
ct=0;
for(int j=0;j<n-i;j++)
{
if(selt<ary[j])
{
selt=ary[j];
ct=j;
}
}
tp=ary[ct];
ary[ct]=ary[n-i-1];
ary[n-i-1]=tp;
}
}
void CSort::my_sort2(int *ary,int n)
{
int tp;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(ary[j]>ary[j+1])
{
tp=ary[j];
ary[j]=ary[j+1];
ary[j+1]=tp;
}
}
}
}
#include "stdafx.h"
#include "Sort.h"
#include <iostream>
using namespace std;
void main()
{
cout<<"Please input the elements for the array:"<<endl;
int ary[10];
for(int i=0;i<10;i++)
cin>>ary[i];
CSort m_Sort;
m_Sort.my_sort1(ary,10);
getchar();
for(int i=0;i<10;i++)
cout<<ary[i]<<" ";
cout<<endl;
m_Sort.my_sort2(ary,10);
getchar();
for(int i=0;i<10;i++)
cout<<ary[i]<<" ";
getchar();
return 0;
}