Question: Sort the array of StaffMembers based on name using the updated selection OR insertion sort from Sorting.java. Put the sort method in the class that

Sort the array of StaffMembers based on name using the updated selection OR insertion sort from Sorting.java. Put the sort method in the class that has direct access to the array. Then call the sort in main before calling payday

//******************************************************************** // Sorting.java Author: Lewis/Loftus // // Demonstrates the selection sort and insertion sort algorithms. //********************************************************************

public class Sorting { //----------------------------------------------------------------- // Sorts the specified array of objects using the selection // sort algorithm. //----------------------------------------------------------------- public void selectionSort(Comparable [] list) { int min; Comparable temp;

for (int index = 0; index < list.length-1; index++) { min = index; for (int scan = index+1; scan < list.length; scan++) // This condition put the value in descending order if (list[scan].compareTo((T)list[min]) > 0) min = scan;

// Swap the values temp = list[min]; list[min] = list[index]; list[index] = temp; } }

//----------------------------------------------------------------- // Sorts the specified array of objects using the insertion // sort algorithm. //----------------------------------------------------------------- public void insertionSort (Comparable[] list) { for (int index = 1; index < list.length; index++) { Comparable key = list[index]; int position = index; // put the values in descending order while (position > 0 && key.compareTo((T)list[position-1]) > 0) { list[position] = list[position-1]; position--; }

list[position] = key; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!