上传文件至「排序」
已优化过有序运行方式
This commit is contained in:
36
排序/maopaopaixu.cpp
Normal file
36
排序/maopaopaixu.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user