Question
Bubble Sort ASSIGNMENT: Write a program to sort an array in ascending order. Ask the user to enter 10 double values into an array, in
Bubble Sort ASSIGNMENT: Write a program to sort an array in ascending order. Ask the user to enter 10 double values into an array, in any order. Then, display the un-sorted array values as entered by the user. Sort the array values using a bubble sort. Finally, display the sorted array values. The algorithm for a simple bubble sort is: Create an outer loop that runs 1 time less than the number of elements in the array. This controls the number of passes for the bubble sort. Create an inner loop that runs 1 time less than the number of elements in the array minus the count of the outer loop. This controls the number of comparisons for each pass of the bubble sort. Inside the inner loop, compare adjacent elements. If they are out of order, swap the elements. Remember, to swap array elements, a temporary variable is necessary. Example Run #1: (bold type is what is entered by the user) Enter a value for array element [0]: 5.6 Enter a value for array element [1]: 9.1 Enter a value for array element [2]: 11.5 Enter a value for array element [3]: 3.1 Enter a value for array element [4]: 0.2 Enter a value for array element [5]: 0.8 Enter a value for array element [6]: 1.4 Enter a value for array element [7]: 6.0 Enter a value for array element [8]: 4.7 Enter a value for array element [9]: 7.4 The un-sorted array: 5.60 9.10 11.50 3.10 0.20 0.80 1.40 6.00 4.70 7.40 The sorted array: 0.20 0.80 1.40 3.10 4.70 5.60 6.00 7.40 9.10 11.50 Write in C program. Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started