<1> quick sorting using arrays with sorting methods
<span style= "Font-family:simsun;font-size:18px;color: #000099;" >import java.util.Arrays; 2 public class test2{public static void Main (string[] args) { int[] a={5,4,2,4,9,1}; Arrays.sort (a); Sort for (int i:a) { System.out.print (i);} } } </span>
<2> bubble Sorting algorithm
public static int[] Bubblesort (int[] args) {//bubble sort algorithm for (int. i=0;i<args.length-1;i++) {for (int j=i+1;j< args.length;j++) { if (Args[i]>args[j]) { int temp=args[i]; ARGS[I]=ARGS[J]; Args[j]=temp ; }}} return args;
<3> Selection Sorting algorithm
<span style= "Font-family:simsun;font-size:18px;color: #000099;" >public static void Selectsort (Int[]a) { int minindex=0; int temp=0; if ((a==null) | | | (a.length==0)) return; The minimum Data array for the for (int i=0;i<a.length-1;i++) {minindex=i;//unordered region subscript for (intj=i+1;j<a.length;j++) { //Find the smallest data in the unordered area and save its array subscript if (A[j]<a[minindex]) { minindex=j; } } if (minindex!=i) { //if the minimum position of the unordered area is not the default first data, then the interchange. Temp=a[i]; A[i]=a[minindex]; a[minindex]=temp;}}} </span>
<span style= "Font-family:simsun;font-size:24px;color: #3333ff;" ><strong><4> Insert Sort Algorithm </strong></span>
<span style= "Font-size:18px;color: #6600cc;" >public Static int[] Insertsort (int[] args) {if (args==null| | ARGS.LENGTH<2) {return args;} for (int i=1;i<args.length;i++) {for (int j=i;j>0;j--) { if (args[j]<args[j-1]) { int TEMP=ARGS[J-1]; ARGS[J-1]=ARGS[J]; args[j]=temp; } else break; } } return args; } </span>
Four kinds of sorting methods in Java using arrays