冒泡排序算法
#include<iostream>
using namespace std;
int main(){
int array[] = {4,3,0,9,1,5,6,8,7,24,66,57};
int data = sizeof(array) / sizeof(array[0]);
cout << "排序算法排序前:" << endl;;
for(int i = 0; i < data; i++){
cout << array[i] << " ";
}
cout << endl;
for(int j = 0; j < data - 1; j++){
for(int e = 0; e < data - j - 1; e++){
if(array[e] > array[e+1]){
int temp = array[e];
array[e] = array[e + 1];
array[e + 1] = temp;
}
}
}
cout << "排序算法排序前后:" << endl;
for(int i = 0; i < data; i++){
cout << array[i] << " ";
}
cout << endl;
return 0;
}
|