Write and run a C++ program that has a 20-element database (array) called dB[ ] with the elements declared as shown below:
const int NUM_ELE = 20;
char dB[NUM_ELE] = { 'x','b','A','X','w','T','M','e','n','Z','z','d','Q','L','K','j','S','v','q','R'};
Provide a function called bub_sort() that uses a bubble (exchange) sort to reorder the elements (capitals in ascending alphabetic order first, then lower-case letters in ascending alphabetic order.) This function must track the total number of moves in reordering the array and provide that number in the function "return." The function must have dB[ ] passed to it (by reference) along with the number of elements in the database (by value). AFTER the function is called in main(), display the total number of moves required and show the reordered array for each of the 20 elements (indicate the INDEX number for each element). Be sure to properly document your program and provide a descriptive display.
I got the alphabetical orders, but how do I count the total number of moves?
What I have tried:
#include<iostream> //library needed
using namespace std;
int bubbleSort(char[], char);
int main() {
const int NUM_ELE = 20; char dB[NUM_ELE] = { 'x','b','A','X','w','T','M','e','n','Z','z','d','Q','L','K','j','S','v','q','R'};
int i, moves;
char temp;
cout<< " This program sort the the 20 elements in alphabetic order"<<endl;
for(int i = 0; i < NUM_ELE; i++)
for(int j = 0; j < NUM_ELE-1; j++)
{
if(dB[j+1] < dB[j])
{
temp = dB[j];
dB[j] = dB[j+1];
dB[j+1] = temp;
}
}
for(int i = 0; i < NUM_ELE; i++)
cout<<dB[i] <<" ";
return 0;
}