/**. The sort method of this class sorts an array, usin
Added on -2019-09-20
| 1 pages
| 130 words
| 143 views
Trusted by 2+ million users, 1000+ happy students everyday
/**The sort method of this class sorts an array, using the insertion sort algorithm.*/public class InsertionSorter{/**Sorts an array, using insertion sort.@param a the array to sort*/public static void sort(int[] a){for (int i = 1; i < a.length; i++){int next = a[i];// Move all larger elements upint j = i;while (j > 0 && a[j - 1] > next){a[j] = a[j - 1];j--;}// Insert the elementa[j] = next;}}}
Found this document preview useful?
You are reading a preview Upload your documents to download or Become a Desklib member to get accesss