# 【精彩好文】教你深入认识排序算法

```class Solution {
public int[] sortArray(int[] nums) {
int len = nums.length;
for (int i = 0; i  nums[j]) {
swap(nums,i,j);
}
}
}
return nums;
}
public void swap(int[] nums,int i,int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
```

```class Solution {
public int[] sortArray(int[] nums) {
int len = nums.length;
for (int i = 0; i  nums[j+1]) {
swap(nums,j,j+1);
}
}
}
return nums;
}
public void swap(int[] nums,int i,int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
```

```class Solution {
public int[] sortArray (int[] nums) {
int len = nums.length;
//标志位
boolean flag = true;
//注意看 for 循环条件
for (int i = 0; i  nums[j+1]) {
swap(nums,j,j+1);
//发生交换，则变为true,下次继续判断
flag = true;
}
}
}
return nums;
}
public void swap (int[] nums,int i,int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
```

```class Solution {
public int[] sortArray(int[] nums) {
int len = nums.length;
int min = 0;
for (int i = 0; i  nums[j]) min = j;
}
if (min != i) swap(nums,i,min);
}
return nums;
}
public void swap (int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
```