数据结构-冒泡排序

时间:2014-05-08 21:59:19   收藏:0   阅读:264
bubuko.com,布布扣
#include <iostream>

using namespace std;

void BubbleSort(int* a,int n){
    for(size_t i=0;i<n;i++){
        for(size_t j=0;j<n-i;j++){
            if(a[j] > a[j+1]){
                int tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
            }
        }
    }
}

int main()
{
    int a[] = {1,5,8,9,6,4,7,2,3,0};
    int n = 10;
    BubbleSort(a,n);

    for(size_t i=0;i<n;i++){
        cout << a[i] << " ";
    }

    return 0;
}
bubuko.com,布布扣

 

数据结构-冒泡排序,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!