Question: Sorting a Dynamic Array of Characters: Let us develop a C++ program that does the following: 1. The program first asks user to enter the

Sorting a Dynamic Array of Characters: Let us develop a C++ program that does the following:

1. The program first asks user to enter the number of elements for an array. Lets call this number N.

2. It then creates a dynamic array of size N + 1, containing N random lowercase alphabet letters between a and z. Make sure the last element is a null character \0. Here, make sure to use dynamic memory allocation (using new command) to allocate memory space for the array, which is exactly why we call it a dynamic array.

3. After creating the array, the program displays the entire (unsorted) array. Here, you must define and use a function showArray to display the array. This function must have the following protocol: void showArray(char *); Note that it does not pass the array size as a parameter (you dont need it when you use pointer). You are NOT allowed to use array index or array bracket [ ] within this function to access elements. Instead, use pointer to do so.

4. Then apply selection sort to sort the array in ascending order of alphabet letters, then display the entire (sorted) array. You must define and use a function selectionSort to sort the array. This function must have the following protocol: void selectionSort(char *); Note that it does not pass the array size as a parameter (you dont need it when you use pointer). Again, you are NOT allowed to use array index or array bracket [ ] within this function to access elements. Instead, use pointer to do so.

5. Ask if the user wants to continue. If yes, return to Step 1. If no, terminate program. Before going back to Step 1 or terminating the program, make sure to release the memory space occupied by the dynamic array (using delete command).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!