1. Use the sort () in the arrays class in the Javaapi document to sort quickly
Copy 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 Arrays static method sort, sorted in ascending order
for (int show:array) {
System.out.println (show);
}
}
}
2, bubble sort
Copy 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 record maximum value
Array[x]=array[y];
Array[y]=temp;
}
}
}
return array;
}
}
3, select the sort
Copy 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 to the minimum value of x
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;
}
}