冒泡排序是一种非常经典的排序算法,通过相邻两个数之间的比较,调换位置,依次类推,实现代码如下
一般的冒泡排序
#include<iostream>
using namespace std;
void swap(int* a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
void print(int arr[], int n){
for (int j = 0; j < n; j++) {
cout << arr[j] << " ";
}
cout << endl;
}
void BubbleSort(int a[], int len