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

My output displays the final result of the bubble sorted array. Howdo I display

ID: 3609094 • Letter: M

Question

My output displays the final result of the bubble sorted array. Howdo I display the array each time it is swapped? My function needsto print out the content of the entire array each time a swap ismade. Please help!

#include <iostream>
#include <string>
using namespace std;

// Function prototypes
void sortArray(string [], int);
void showArray(string [], int);

int main()
{
   // Array of unsorted values
   string values[7] = {"book", "pen", "desk", "pencil","paper", "chair", "test"};

   // Display the values.
   cout << "Here is the vector in the ORIGINALorder: ";
   cout << " " << endl;
   showArray(values, 7);
   cout << " " << endl;

   // Sort the values.
   cout << "Now demonstrating string BubbleSort inthe descending order: ";
   cout << " " << endl;
   sortArray(values, 7);

   // Display them again.

   showArray(values, 7);
   cout << " " << endl;

   system ("pause");
   return 0;
}

//Bubble sort descending
void sortArray(string array[], int size)
{
   bool swap;
   string temp;

   do
   {
      swap = false;
      for (int count = 0; count < (size- 1); count++)
      {
         if (array[count]< array[count + 1])
         {
           temp = array[count];
           array[count] = array[count + 1];
           array[count + 1] = temp;
           swap = true;
         }
      }
   } while (swap);
}

void showArray(string array[], int size)
{
   for (int count = 0; count < size; count++)
      cout << array[count] <<" ";
   cout << endl;
}

Explanation / Answer

please rate - thanks add a call to show array in the middle of the swap see red line below #include #include using namespace std; // Function prototypes void sortArray(string [], int); void showArray(string [], int); int main() {    // Array of unsorted values    string values[7] = {"book", "pen", "desk", "pencil","paper", "chair", "test"};    // Display the values.    cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote