#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; }
原文:http://www.cnblogs.com/wn19910213/p/3709209.html