Package Test3;public class sort{/** * Bubble sort * @param array */public void Bubblesort (int[] array) {for (int i = 1; i < arr Ay.length; i++) {for (int j = 0; J < Array.length-i; J + +) {if (Array[j] > array[j + 1])//Determine the size of the adjacent two elements {int c = array[j];//Save the first element's Value Array[j] = array[j + 1];//give the second value to the first array[j + 1] = c;//give the first value to the second}}}showarray (array);} /** * Select sort * @param array */public void Selectsort (int[] array) {int index;for (int i = 1; i < Array.Length; i++) {Index = 0;for (int j = 1; J <= Array.length-i; j + +) {if (Array[j] > Array[index])//Find maximum value {index = j;}} int c = Array[array.length-i]; Element last value array[array.length-i] = Array[index]; Put the selected maximum or minimum value on the last value array[index] = c;//The last value to be selected to the maximum or minimum value}showarray (array);} /** * Reverse Sort * @param array */public void Reversesort (int[] array) {SYSTEM.OUT.PRINTLN ("array original value"); Showarray (array); int C;for ( int i = 0; i < ARRAY.LENGTH/2; i++) {//loop array half c = array[i];//Gets the first value, puts the temporary variable array[i] = array[array.length-1-i];//puts the last value on the first value Array[aRray.length-1-I] = c;//Place the first value on the last value on the value}system.out.println ("array reversal value"); Showarray (arrays);} private void Showarray (int[] array) {for (int is:array) {System.out.print ("\ t" +is);} System.out.println ();}}
Three major sorts of Java