1. Use sort() in the Arrays class in the JavaApi documentation for quick sorting
Copy the code code as follows:
import java.util.Arrays;
public class TestOne{
public static void main(String [] args){
int [] array={2,0,1,4,5,8};
Arrays.sort(array);//Call the static method Sort of Arrays to sort in ascending order
for(int show:array){
System.out.println(show);
}
}
}
2. Bubble sorting
Copy the code code as follows:
public class TestTwo{
public static void mian(String []args){
int [] arr={2,0,1,4,6,5};
int [] showArr testMethod(arr);
for(show:showArr){
System.out.println(show);
}
}
public static int [] testMethod(int [] array){
for(int x=0;x<array.length-1;x++){
for(int y=x+1;y<array.length;y++){
if(array [x]>array[y]){
int temp=array[x];//Temporary variable records the maximum value
array[x]=array[y];
array[y]=temp;
}
}
}
return array;
}
}
3. Select sorting
Copy the code code as follows:
public class TestTwo{
public static void mian(String []args){
int [] arr={2,0,1,4,6,5};
int [] showArr testMethod1(arr);
for(show:showArr){
System.out.println(show);
}
}
public static int [] testMethod1(int [] array){
for(int x=0;x<array.length-1;x++){
int min=x;//Set the following table as x as the minimum value
for(int y=x+1;y<array.length;y++){
if(array[max]>array[y]){
min=j
}
}
if(min!=x){
int temp=array[x];
array[x]=array[min];
array[min]=temp;
}
}
return array;
}
}