Answered step by step
Verified Expert Solution
Link Copied!

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.

  1. Make a function Swap( ) that takes address of the two integers variables as arguments (pointers) and swap those two variables.
  2. 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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

Students also viewed these Programming questions

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago

Question

State the uses of job description.

Answered: 1 week ago

Question

Which other character brings out a particular part? And why?

Answered: 1 week ago