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
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[position] = key; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
