Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ Program that sorts an array through bubble sort by swapping values and then finding median of that sorted array. Most importantly write
Write a C++ Program that sorts an array through bubble sort by swapping values and then finding median of that sorted array. Most importantly write your code in the following parts.
- Make a function Swap( ) that takes address of the two integers variables as arguments (pointers) and swap those two variables.
- Make a function BubbleSort( ) which sorts an integer type array into ascending order. The function BubbleSort( ) takes the array and its size as argument.
It uses the above function swap while sorting to swap two array elements by passing those array elements to swap function.
- Make a function Median() that takes an array and its size as arguments. Then it calls the above function BubbleSort() to sort the array. After sorting it will find the mean of that sorted array through following formual.
- Write main program. Take the values of array in it from user. Call only the function named median( ) from main and pass it the array and its size.
3 | 1 | 4 | 1 | 5 | 9 | 2 | 6 | 5 |
Formula for Median of an array in C++
When size of array is even: Median = arr[size/2];
When size of array is odd: Median = ( arr[ size/2 ]+arr[ size/(2+1)] ) / 2.0;
Remember arrays index start from 0.
Step by Step Solution
★★★★★
3.45 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
Solution 1 int swapint a int b int main int a 10 b 2...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