冒泡算法图解
实现代码:
public static void main(String[] args) {
int[] arr={99,55,31,-44,5};
boolean res=false;//优化
for (int i = 0; i arr[j+1]){
res=true;
int x=arr[j];
arr[j]=arr[j+1];
arr[j+1]=x;
}
}
if (!res){
break;
}else {
res=false;
}
}
System.out.println(Arrays.toString(arr));
}



