Question: Need help with this making it into a C++ code The following is the algorithm for the simplest sorting algorithm. It is also generally con-

Need help with this making it into a C++ code

The following is the algorithm for the simplest sorting algorithm. It is also generally con- sidered to be the worst performing sorting algorithm and so is not generally used in any situation where performance is a consideration. Bubble-Sort(A) 1 for i = 1 to length[A] the last i-1 element are in place 2 for j = 1 to length[A] i j and j+1 are compared and swapped if necessary 3 if A[j] > A[j + 1] 4 swap(A[j], A[j + 1]) Write a C++ program that sorts an array of strings using Bubble Sort. Your program should have the following features. Notice that the indexing in this algorithm (and the algorithms in the book) start at 1. In C++ indexing starts at 0. You should take this into account when writing your code. The bubble sort algorithm should be implemented in a function void bubble_sort(string a[], int size) The program should get the input file name as user input. You may assume that the first entry in the file is an integer that indicates the number of strings in the file. The remaining lines will be the strings, one per line. You should create a dynamic array to hold these strings. It is not legal C++ to have a variable as the size of the array (although some compilers will allow this). Instead, you should use the new command to allocate the memory for the array. You should also use the delete command to free the memory when you are done.

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!