首页 留言 登录
bubble冒泡排序,从大往小排函数
#include <bits/stdc++.h> 
using namespace std;

void bubble(int[],int);

int main(){
    int a[10] = {1,2,3,4,5,6,7,8,9,10};
    for(int i=0;i<10;++i){
        cout << a[i] << " ";
    }
    cout << endl;
    bubble(a,10);
    for(int i=0;i<10;++i){
        cout << a[i] << " ";
    }
    return 0;
}

void bubble(int a[],int n){
    for(int i=1;i<n;++i){
        for(int j=0;j<n-i;++j){
            if(a[j]<a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }
}


上一篇:例6.7写一个是否是素数的函数
下一篇:例6.4定义一个函数check(n,d),如果数字d在正整数n的某位中出现,则返回true,否则返回false
验证码
评论留言 (0条)