Question

In: Computer Science

Make quicksort functions to sort this class, first by ID then by athleteEvaluation athleteID: an unique...

Make quicksort functions to sort this class, first by ID then by athleteEvaluation

athleteID: an unique identifier for the athlete

athletePosition: an abbreviation of the expected player’s position on the team. We will use an enumerated data type to store the position within our BUAthlete class. A definition of the enumerated data type is provided below. Don't forget that enumerated data types are actually stored as integers.

enum Position {OL, QB, RB, WR, TE, DL, DE, LB, CB, S, K}; 

CLASS:

class BUAthlete : public NCAAAthlete{
protected:
int athleteID2;
string athletePosition;
int athleteEvaluation;

public:
void setID2(int id);
void setathletePosition(string pos);
void setEval(int eval);
int getID2();
string getathletePosition();
int getEval();
string toString();
};

Solutions

Expert Solution

HELLO

I HAVE DESIGNED 2 FUNCTIONS OF QUICK SORT TO SORT BY AS PER YOUR REQUIREMENT

PLEASE GO THROUGH IT

void swap(BUAthlete* a, BUAthlete* b) 
{ 
    BUAthlete t = *a; 
    *a = *b; 
    *b = t; 
} 
/* This function takes last element as pivot, places 
   the pivot element at its correct position in sorted 
    array, and places all smaller (smaller than pivot) 
   to left of pivot and all greater elements to right 
   of pivot */
int partitionByID (BUAthlete arr[], int low, int high) 
{ 
    int pivot = arr[high].getID2();    // pivot 
    int i = (low - 1);  // Index of smaller element 
  
    for (int j = low; j <= high- 1; j++) 
    { 
        // If current element is smaller than or 
        // equal to pivot 
        if (arr[j].getID2() <= pivot) 
        { 
            i++;    // increment index of smaller element 
            swap(&arr[i], &arr[j]); 
        } 
    } 
    swap(&arr[i + 1], &arr[high]); 
    return (i + 1); 
} 
  
/* The main function that implements QuickSort 
 arr[] --> Array to be sorted, 
  low  --> Starting index, 
  high  --> Ending index */
void quickSortById(BUAthlete arr[], int low, int high) 
{ 
    if (low < high) 
    { 
        /* pi is partitioning index, arr[p] is now 
           at right place */
        int pi = partitionByID(arr, low, high); 
  
        // Separately sort elements before 
        // partition and after partition 
        quickSortById(arr, low, pi - 1); 
        quickSortById(arr, pi + 1, high); 
    } 
} 



int partitionByEval(BUAthlete arr[], int low, int high) 
{ 
    int pivot = arr[high].getEval();    // pivot 
    int i = (low - 1);  // Index of smaller element 
  
    for (int j = low; j <= high- 1; j++) 
    { 
        // If current element is smaller than or 
        // equal to pivot 
        if (arr[j].getEval() <= pivot) 
        { 
            i++;    // increment index of smaller element 
            swap(&arr[i], &arr[j]); 
        } 
    } 
    swap(&arr[i + 1], &arr[high]); 
    return (i + 1); 
} 
  
/* The main function that implements QuickSort 
 arr[] --> Array to be sorted, 
  low  --> Starting index, 
  high  --> Ending index */
void quickSortByEval(BUAthlete arr[], int low, int high) 
{ 
    if (low < high) 
    { 
        /* pi is partitioning index, arr[p] is now 
           at right place */
        int pi = partitionByEval(arr, low, high); 
  
        // Separately sort elements before 
        // partition and after partition 
        quickSortByEval(arr, low, pi - 1); 
        quickSortByEval(arr, pi + 1, high); 
    } 
} 




Related Solutions

give a good explanation of Bubble sort, Insertion sort, Selection sort, and Quicksort.
give a good explanation of Bubble sort, Insertion sort, Selection sort, and Quicksort.
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
The purpose here is to implement the QuickSort sorting algorithm to sort integers. Write a C...
The purpose here is to implement the QuickSort sorting algorithm to sort integers. Write a C program which accepts 1 command-line argument: the name of a text file which contains integers, one-per line. Your C program must be named project3. Your C program needs to implement the QuickSort algorithm to sort the integers read from the file specified on the command-line. Your QuickSort implementation must utilize the median-of-three algorithm for choosing a pivot, and BubbleSort any sub arrays with less...
c++ Run the following sorting algorithms: 1. Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort...
c++ Run the following sorting algorithms: 1. Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort Under the following scenarios for input data: 1. Uniform random 2. Almost sorted (90% sorted – 1 in 10 is out of place) 3. Reverse sorted On data of sizes 5,000, 10,000, … in increments of 5,000 up to …, 50,000 -Attach a screenshot of a program compilation below -Attach a screenshot of a successful program run below -Attach a graph (either line graph...
make a Pay class that had fields for a single employee's name, ID number, hourly pay,...
make a Pay class that had fields for a single employee's name, ID number, hourly pay, number of hours worked. use appropriate getter and setter methods, and a constructor accepting the employees name, ID number, hourly pay, and number of hours worked as arguments. The Pay class should also have a method that returns the employee's gross pay (gross pay = hourly pay* number of hours worked). In addition include a toString method that prints to screen the employee name,...
If quicksort is so quick, why bother with anything else? If bubble sort is so bad,...
If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many different sorting algorithms? Your task is to investigate these and other questions in relation to the algorithms selection sort, insertion sort, merge sort, and quicksort. Write a set of guidelines for each algorithm to help someone decide which one would be most appropriate for a particular situation. Include in your guidelines a...
Can someone implement the following in Java? Quicksort with switching to Insertion sort when the number...
Can someone implement the following in Java? Quicksort with switching to Insertion sort when the number of elements in the subarray is less than or equal to 2% of the original number Requirements: 1) functions from standard libraries implementing Quicksort are NOT allowed;
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT