1、选择排序
![选择排序思路](https://i-blog.csdnimg.cn/blog_migrate/48bd1c70dc7f6dac93e084e88b6f9743.jpeg)
int[] array = {2,9,5,36,19,78};
System.out.println(Arrays.toString(array));
for (int i = 0; i < array.length; i++) {
//将索引为i的数据与后面的值一次比较
for (int j = i+1; j < array.length; j++) {
int temp = 0 ;
if(array[i] > array[j]){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
2、冒泡排序
![冒泡排序](https://i-blog.csdnimg.cn/blog_migrate/f521869f17f826c6aabce35d0c42233d.jpeg)
int[] arr = {3,6,4,89,12,45};
System.out.println(Arrays.toString(arr));
//限制每次循环比较的个数(最后的总是不必比较的)
for (int i = arr.length; i > 0; i--) {
for (int j = 0; j < i-1; j++) {
if(arr[j] > arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}