Sorting and Swap Sorting is the process of arranging data in a collection (usually an array) so…
Sorting and Swap Sorting is the process of arranging data in a collection (usually an array) so that it is ordered usually from smallest to largest or from first to last. For example, given an array that has the three strings “i”, “c”, and “s”, sorting the array would place the three strings in the order “c”: “1”, and “s”. An array with the numbers 3, 1,4, 1,5.9.2.6.5.3 (the first 10 digits of pi) would be sorted to have the numbers in the order 1. 1. 2. 3.3.4.5.5.6.9. Two out of the three sorting algorithms we have presented so far can be implemented with an underlying swap operation that swaps adjacent elements of an array. This operation is defined as: @param: the array within which to swap the two elements @param: swap the elements at positions index and index + 1 * @throws: if index < or index > data.length 2 public static void swapAdjacent(E[] data, int index) throws java.lang. ArrayIndexOutOfBoundsException { E swap = data[index]; data[index] = data[index + 1]; data[index + 1] = swap; } Note the unusual type notation E. This is a type parameter, and will be discussed in class once we start talking about collections. For this assignment, you should use it as you would any other type.