#include<iostream>
using namespace std;
void order(int *s);
int main()
{
int a[10]={5,3,2,4,1,7,10,8,6,9};
cout<<"original a=";
for(int i=0;i<10;++i)
{
cout<<a[i]<<" ";
}
order(a);
cout<<endl<<"new a=";
for(int i=0;i<10;++i)
{
cout<<a[i]<<" ";
}
return 0;
}
void order(int *s)
{
for(int i=0;i<10;i++)
for(int j=9;i<j;j--)
{
if(s[i]>s[j])
{
int t=s[j];
s[j]=s[i];
s[i]=t;
}
}
}
/*
//--------------------------=------------------------------
#include <iostream>
using namespace std;
const int ARRAYLEN = 10;
///
///升序排列,依次寻找最小值,O(n^2)
void AscOrder(int *orgArr,int arrLen)
{
int chgTmp;
for(int i=0 ;i<arrLen ;i++)
for(int j=arrLen-1 ;i<j ;j--)
{
if(orgArr[i] > orgArr[j])
{
chgTmp = orgArr[i];
orgArr[i] = orgArr[j];
orgArr[j] = chgTmp;
}
}
}
///
///打印数组函数
void PrintArray(int *arr,int arrLen)
{
for(int i=0;i<arrLen;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
int main()
{
int orgArray[ARRAYLEN] = {4,7,3,9,1,0,8,2,5,6};
cout<<"The original array : ";
PrintArray(orgArray,ARRAYLEN); //打印原始数组
AscOrder(orgArray,ARRAYLEN); //升序排列
cout<<"The new array : ";
PrintArray(orgArray,ARRAYLEN); //打印出升序排列后的数组
return 0;
}
*/
修改了一下。。。。:lol: |