There are many sorting techniques basics are
Insertion Sort
Bubble Sort
public class Sorting {
public static void main(String[] args) { int a[] = {5,3,4,2,1}; bubbleSortAsc(a);
System.out.println(Arrays.toString(a));
}
static void insertionSortAsc(int a[]){ int bucket = -1; for(int i=0; i<a.length-1; i++){ for(int j=i+1; j<a.length; j++){ if(a[i] >a[j]){ bucket = a[i]; a[i] = a[j]; a[j] = bucket; } } } }
static void bubbleSortAsc(int a[]){ int bucket = -1; for(int i=0; i<a.length-1; i++){ for(int j=0; j<a.length-i-1; j++){ if(a[j] >a[j+1]){ bucket = a[j]; a[j] = a[j+1]; a[j+1] = bucket; } } } }
There was an error while loading. Please reload this page.