十大内部排序算法:
选择排序:直接选择排序,堆排序
交换排序:冒泡排序,快速排序
插入排序:直接插入排序,折半插入排序,Shell排序
归并排序
桶式排序
基数排序
冒泡排序:
package MyJava.SuanFa;
//冒泡排序的实现
public class BubbleSort {
public static void main(String[] ags){
int[] arr = new int[]{25,22,36,85,44,98,66};
/*
冒泡排序
*/
for(int i =0;i< arr.length-1;i++){
for (int j = 0 ;j< arr.length-1-i;j++){
if (arr[j]>arr[j+1]){
int temp = arr[j];
arr[j]= arr[j+1];
arr[j+1]=temp;
}
// else {
// arr[j]=arr[j];
// arr[j+1]= arr[j+1];
// }
}
}
for (int i = 0 ;i< arr.length;i++){
System.out.println(arr[i]);
}
}
}
快速排序:
好如:细胞分裂一样
package MyJava.SuanFa;
//快速排序
public class QuickSort {
private static void swap(int[] data,int i ,int j){
int temp = data[i];
data[i] =data[j];
data[j]= temp;
}
private static void subSort(int[] data, int start,int end){
if (start<end){
int base =data[start];
int low = start;
int high = end + 1;
while (true){
while ( low < end && data[++low]<=base);
while (high >start && data[--high]>=base);
if (low <high){
swap(data,low,high);
}else {
break;
}
}
swap(data,start,high);
subSort(data,start,high-1);
subSort(data,high+1,end);
}
}
public static void quickSort(int[] data){
subSort(data,0,data.length-1);
}
public static void main(String[] ags){
int[] data={9,-2,-88,56,151,632,585,66,6652,56,15,48,48,32};
quickSort(data);
System.out.println(java.util.Arrays.toString(data));
}
}