Skip to content
Farrukh Ahmad edited this page Dec 15, 2015 · 1 revision

There are many sorting techniques basics are

  1. Insertion Sort

  2. 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; } } } }

    }

Clone this wiki locally