Package Simplesort;public class Simplesort {/** * bubble sort: Each cycle, the small number of rows in the back will be as slowly as the bubbles in the water, so named bubble sort, I guess this is ... public void Bubblesort (int[] array) {for (int. i=0;i<array.length;i++) {for (int j=array.length-1;j>i;j--) {// Note here that J is from the back-forward loop if (Array[j-1]>array[j]) {//If the preceding number is larger than the number after it, swap their two positions swap (ARRAY,J);}}} /** * Simple selection Sort: The basic idea is to start with the first number, each time you choose the smallest number that is smaller than his/her position * @param array */public void Selectsort (int[] array) {int min;for (int i= 0;i<array.length-1;i++) {min=i;for (int j=i+1;j<=array.length-1;j++) {//Select the ratio of the array after I Array[i] Small minimum number and keep its subscript in min if (Array[min]>array[j]) {min=j;}} if (min!=i) {swap (array,i,min);}}} /** * Direct Insertion Sort: the idea of direct insertion sort is similar to the way we constantly touch and arrange the landlord when we are in daily life. * We will follow the cards in the back of the card from small to large insert into the corresponding position * @param array */public void Insertsort (int[] array) {int i,j,temp;for (i=1;i<array.length;i++) {if (array[i]<array[i-1]) {temp=array[i];for (j=i-1;j>=0&&array[j]>temp;j--) {//Be careful not to ignore j>=0, otherwise Ken can appear j=-1, causing the array to cross ARRAY[J+1]=ARRAY[J];} array[j+1]=temp;}}} Swap PubLIC void swap (int array[],int i,int j) {int temp=array[i];array[i]=array[j];array[j]=temp;} Exchange public void Swap (int array[],int j) {int temp=array[j-1];array[j-1]=array[j];array[j]=temp;}}
Java Data Structure Series-simple sorting: bubbling, simple selection, direct insertion