Public classTest { Public Static voidMain (string[] args) {intA[] = {1, 2, 3, 4, 5 }; //Select Sort (a); //Insert Sort (a);Quicksort (A, 0, a.length-1); System.out.print ("After sorting:"); for(intn:a) {System.out.print (n+ " "); } } Static voidSelect Sort (int[] a) {intpos = 0; for(inti = 0; i < a.length-1; i++) {pos=i; //maximum value after positioning to I for(intj = i; J < A.length; J + +) { if(A[pos] <A[j]) {POS=J; } } //Max value and I value Exchange intt =A[pos]; A[pos]=A[i]; A[i]=T; } } Static voidInsert Sort (int[] arr) { for(inti = 1; i < arr.length; i++) {System.out.print (i+ ":"); //Assuming (0-> (j-1)) is orderly, see where J Platoon for(intj = i; J > 0; j--) { if(Arr[j] > Arr[j-1]) { inttemp =Arr[j]; ARR[J]= Arr[j-1]; Arr[j-1] =temp; } Else { //Assuming that the front is ordered, you only need to swap once. Break; } } for(intN:arr) {System.out.print (n+ " "); } System.out.println (); } } Static voidQuicksortintArr[],intLeftintRight ) { if(Left <Right ) { //Locate the left intKey =Arr[left]; inti =Left ; intj =Right ; while(I <j) { while(I < J && Arr[j] <key) { //high standard left move ←j--; } if(Arr[i]! =Arr[j]) { //High: Small to the left to pullArr[i] =Arr[j]; } while(I < J && Arr[i] >key) { //low mark right shift →i++; } if(Arr[i]! =Arr[j]) { //Low: Large to the right pullARR[J] =Arr[i]; }} Arr[i]=key; Quicksort (arr, left, I-1); Quicksort (arr, I+ 1, right); } }}
Java Select Sort, insert sort, quick sort