Question: (Exercise) Create sortArray1.cpp Implement Bubble Sort. Bubble Sort goes through the array and repeatedly swaps adjacent elements if they are in incorrect order. Bubble Sort

(Exercise) Create sortArray1.cpp Implement Bubble Sort. Bubble Sort goes through the array and repeatedly swaps adjacent elements if they are in incorrect order. Bubble Sort repeats the previous step on the unsorted portion of the array, which decreases by one each time. The algorithm terminates when the unsorted portion of the array goes to zero.

EX: FIRST PASS: [9 7 1 4 3] -> [7 9 1 4 3]: Swap since 9 > 7 [7 9 1 4 3] -> [7 1 9 4 3]: Swap since 9 > 1 [7 1 9 4 3] -> [7 1 4 9 3]: Swap since 9 > 4 [7 1 4 9 3] -> [7 1 4 3 9]: Swap since 9 > 3 The algorithm repeats the same steps on all the elements in the array except the last element, since it is already sorted. The unsorted portion of the array decreases by one each time until it goes to 1, at which time the algorithm terminates.

Specifically, you should ask the user to enter the size of the array, by outputting: Enter the size of the array: to the console. If the user enters an incorrect size, you should output the error message ERROR: you entered an incorrect value for the array size!and exit the program. If the input is a valid size for the array, ask the user to enter the data, by outputting Enter the numbers in the array, separated by a space, and press enter:

Let the user enter the numbers of the array and store them into a C++ array. Example runs (input is in italic and bold): Enter the size of the array: 5 Enter the numbers in the array, separated by a space, and press enter: 9 7 1 4 3 This is the sorted array in ascending order: 1 3 4 7 9

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!