用指针变量作函数形参接收数组地址,解决10个整数按由大到小顺序排序问题

#include <iostream>
using namespace std;

void select_Sort(int *p,int n){
    int i,j,k,t;
    for(i=0;i<n-1;i++){
        k=i;
        for(j=i+1;j<n;j++){
            if(*(p+j)<*(p+k))
                k=j;
            t=*(p+k);
            *(p+k)=*(p+j); 
            *(p+j)=t;
        }
    }
}
int main(){
    int a[10],i;
    cout<<"enter the original array:"<<endl;
    for(i=0;i<10;i++){
        cin>>a[i];
    }
    cout<<endl;
    select_Sort(a,10);
    cout<<"the sorted array:"<<endl;
    for(i=0;i<10;i++){
        cout<<a[i]<<"  ";
    }
    cout<<endl;
    return 0;
}

 

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-06-14
相关资源
相似解决方案