Question: write a program that sorts an array using various sorting algorithms and utilizing 4 different data types and prints the number of comparisions, number of





![the numbers */ 3 public static void insertionSort(int[] list) { 4 for](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f0f74925527_97666f0f7489c9c1.jpg)
LISTING 23.1 InsertionSort.java 1 public class InsertionSort { 2 /** The method for sorting the numbers */ 3 public static void insertionSort(int[] list) { 4 for (int i = 1; i = 0 && list[k] > currentElement; k--) { 10 list[k + 1] = list[k]; 11 } 12 // Insert the current element into list[k + 1] 14 list[k + 1] = currentElement; 15 } 16 17 } ING 7.8 Selection Sort.java public class Selection Sort { /** The method for sorting the numbers */ public static void selection Sort(double[] list) { for (int i = 0; i list[j]) { currentMin = list[j]; currentMinIndex - j; } } // Swap list[i] with list[currentMinIndex] if necessary if (currentMinIndex != i) { list[currentMinIndex] = list[i]; list[i] = currentMin; } } 3} 16 LISTING 23.8 QuickSort.java public class QuickSort { 2 public static void quickSort(int[] list) { 3 quick Sort(list, 0, list. length - Di 4 } 5 6 public static void quickSort(int[] list, int first, int last) { 7 if (last > first) { 8 int pivotIndex partition(list, first, last): 9 quickSort(list, first, pivotIndex - 1): 10 quickSort(list, pivotIndex +. 1, last): 11 1 12 } 13 14 ** Partition the array list[first..last] 15 public static int partition(int[] list, int first, int last) { int pivot = list[first]: // Choose the first element as the pivot 17 int low - first + 1; // Index for forward search 18 int high - last; // Index for backward search 19 20 while (high > low) { 21 // Search forward from left 22 while (low pivot) 27 high- 28 29 11 Swap two elements in the list 30 if (high > low) { 31 int temp - list[high): 32 list[high) - Tist[low]: 33 list[low) temp: 34 35 36 37 while Chigh > first & Tist[high] >- pivot) 38 high- 39 40 I/ Swap pivot with list[high) 41 if (pivot > list (high)) { 42 list[first] - list[high): 43 list[high] - pivot; 44 return high: 45 1 46 else { 47 return first; 48 49 LISTING 23.9 Heap.java public class Heap extends comparabled private sava.util.Araylist - java.ut. ArrayListo Create a default heap public Heap W Find the main betwo children if left index ist.si) break // The tree is heap intodex - Tech Index Critiindeks if (st.getCT).compare To get right index)) maxIndex rightChild Index Create a help from an array of objects public Heap CEC objects) C for (int 101
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
