Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void DoInsertionSort(AList& list) { cout << \"\ Performing Insertion Sort onthe

ID: 3617329 • Letter: V

Question

void DoInsertionSort(AList& list)

{

    cout << " Performing Insertion Sort onthe current list." << endl;

    int comparisons = 0;

    int movements = 0;

    list.InsertionSort(comparisons,movements);

    int n = list.getNumberOfElements();

    int theoreticalComparisons = (n * (n -1))/2;

    int theoreticalMovements = (2 * (n - 1)) + (n* (n - 1) / 2);

    cout << " Theoretical sort statistics:"

         <<theoreticalComparisons << " element comparisons, "

         <<theoreticalMovements << " element movements." <<endl;

    cout << "Actual sortstatistics:      "

         <<comparisons << " element comparisons, "

         <<movements << " element movements." << endl;

    cout << " Finishing Insertion Sort."<< endl;

Explanation / Answer

void DoInsertionSort(AList& list)

{

    cout << " Performing Insertion Sort onthe current list." << endl; //displaying text

    int comparisons = 0; //creates variable to be passed tofunction

    int movements = 0; //creates variable to be passed to function

    list.InsertionSort(comparisons, movements);/*calls InsertionSort method from the classlist while passing in comparisons and movements*/

    int n = list.getNumberOfElements();//calls method to find how big the listis

    int theoreticalComparisons = (n * (n - 1))/2;//plugs number into a formula

    int theoreticalMovements = (2 * (n - 1)) + (n* (n - 1) / 2); // plugs number into aformula

    cout << " Theoretical sort statistics:"//output text

         <<theoreticalComparisons << " element comparisons,"//output text

         <<theoreticalMovements << " element movements." <<endl;//output text

    cout << "Actual sortstatistics:      "//output text

         <<comparisons << " element comparisons, "//output text

         <<movements << " element movements." << endl;//output text

    cout << " Finishing Insertion Sort."<< endl;//output text