#include <iostream>
#include <vector>
#include <stack>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include "TreeNode.h"
using namespace std;
void mySwap(int num[], int i, int j){
int temp= num[i];
num[i] = num[j];
num[j] = temp;
}
// 从下往上冒泡
void BubbleSort(int num[], int length){
int i, j;
bool flag = true;
for(i = 0; i < length - 1 && flag; i++){
flag = false;
for(j = length - 2; j >= i; j--){
if(num[j] > num[j+1]){
flag = true;
mySwap(num, j, j+1);
}
}
}
}
int main(int argc, char* argv[]){
int arr[6] = {4,5,6,3,2,1};
BubbleSort(arr, sizeof(arr)/sizeof(arr[0]));
for(int i = 0; i < 6; i++){
cout<<arr[i]<<"\t";
}
return 0;
}
原文:https://www.cnblogs.com/flyingrun/p/13411734.html