When we talk about algorithms, Sorting and Searching is quite significant. There are few sorting and searching algorithms. Today I'm going to present you the java implementation of Insertion sort.
int[] insertion_sort(int[] x){ int key = 0; for(int j=1 ; x.length > j ; j++){ key = x[j]; while(i > 0 && x[j] > key){ x[i+1] = x[i]; i = i - 1; } x[i+1] = key; } return x; }In the next post I hope to implement quick sort.
References : Introduction to Algorithms 3rd ed. T. Cormen...