#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define Max 11
int main(){
int length;
cout<<"input the length:";
cin>>length;
int data[length+1];
cout<<"input the array:";
for(int i=1;i<=length;i++){
int a;
cin>>a;
data[i]=a;
}
for(int i=length;i>1;i--){
int flag=0;
for(int j=2;j<=i;j++){
if(data[j]<data[j-1]){
int t=data[j];
data[j]=data[j-1];
data[j-1]=t;
flag=1;
}
}
if(!flag)break;
for(int ii=1;ii<length;ii++){
cout<<data[ii]<<" ";
}
cout<<endl;
}
}
c语言数据结构--冒泡排序
最新推荐文章于 2024-10-10 20:14:35 发布