1. Bubble Sorting: Same as fast sorting, it is a type of exchange sorting.
public class Sort{ public void generatArray(int [] array){ Random random = new Random(); for (int i=0;iarray[j+1]){ tmp=array[j]; array[j]=array[j+1]; array[j+1]=tmp; } } } for (int a : array) { System.out.print(a+","); } System.out.println(); } public static void main(String args[]){ Sort sort = new Sort(); int array[]=new int[10]; sort.generatArray(array); sort.bubbleSort(array); }}
2. Fast sorting: Improves the Bubble sorting.
Public class Sort {public void generatArray (int [] array) {Random random = new Random (); for (int I = 0; I = r) return; int k = array [l]; int I = l, j = r; while (I
3. Insert sorting:
public class Sort{ public void insertSort(int [] array){ for(int i=1;i0 && array[j-1]>tmp;j--) array[j]=array[j-1]; array[j]=tmp; } for (int a : array) { System.out.print(a+","); } System.out.println(); } public static void main(String args[]){ Sort sort = new Sort(); int array[]=new int[10]; sort.generatArray(array); sort.insertSort(array); }}