1, insert the sorting method (with relatively few).
public class insertsort{
public static void Main (String [] args) {
int [] array={2,6,3,9,5,22,19,26,11};
for (int i=1;i<array.length;i++) {
int temp=array[i];
int j=i;//Save the subscript.
while (J>0&&temp<array[j-1]) {
The above number overrides the number below it
ARRAY[J]=ARRAY[J-1];
j--;
}
array[j]=temp;//Inserting data
}
for (int i=0;i<array.length;i++) {
System.out.print (array[i]+ "");
}
}}
2, select the sorting method (from the array to find the largest or smallest data for one by one comparison)
public class selectsort{
public static void Main (String [] args) {
int [] array={1,5,4,6,8,90,45,22,87,212,447};
int min=0;
for (int i=0;i<array.length-1;i++) {
min=i;//The first one is the smallest first.
for (int j=i+1;j<array.length;j++) {
if (Array[min]>array[j]) {
Min=j;
}
}
If the minimum number of I is not located on I, then the Exchange
if (i!=min) {
int temp=array[i];
Array[i]=array[min];
Array[min]=temp;
}
}
for (int i=0;i<array.length;i++) {
System.out.print (array[i]+ "");
}
}}
Java Array 4 (2015-8-27)