冒泡法倒排序
![](https://img2020.cnblogs.com/blog/1725997/202003/1725997-20200312161850529-874801649.png)
```java for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length - i - 1; j++) { if(a[j] > a[j + 1]) { b = a[j]; a[j] = a[j + 1]; a[j + 1] = b; } } } ```
####选择法正排序 和冒泡排序相比,循环的次数没有减少,但减少了数据交换的次数
![](https://img2020.cnblogs.com/blog/1725997/202003/1725997-20200313095748530-965900680.png)
```java for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if(a[i] > a[j]) { b = a[i]; a[i] = a[j]; a[j] = b; } } }
for (int i = 0; i < a.length; i++) {
int k = i;
for (int j = i + 1; j < a.length; j++) {
if(a[k]>a[j]) {
k = j;
}
}
if(k != i) {
b = a[i];
a[i] = a[k];
a[k] = b;
}
}
<br/>