上传文件至「排序」

冒泡排序已经优化
This commit is contained in:
2026-02-07 02:59:10 -05:00
parent a5c40a07eb
commit d6ac37f3e4

36
排序/maopaopaixu.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n=5,max;
bool bl=false;
int a[n]={12,22,81,94,95};
for(int i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
if(a[j]>a[j+1]){
max=a[j];
a[j]= a[j+1];
a[j+1]=max;
bl=true;
}
if (!bl)
break;
}
}
for(int j=0;j<n;j++)
cout<<a[j]<<" ";
cout<<endl;
return 0;
}