Question
I have the code in Java. I need the same in C++ but by pass by reference. class BubbleSort { // function to sort array
I have the code in Java. I need the same in C++ but by pass by reference.
class BubbleSort
{
// function to sort array a using bubble sort
public static void bubble_sort(int a[])
{
int i, j, x;
for( i = 0 ; i < a.length - 1 ; i++)
{
for( j = 0 ; j < a.length - i - 1 ; ++j)
{
if (a[ j + 1 ] < a[ j ])
{
// swap the j and j + 1 th element of a
x = a[j];
a[ j ] = a[ j + 1 ];
a[ j + 1 ] = x;
}
}
}
}
public static void display(int a[])
{
int n = a.length;
for (int i=0; i<n; ++i)
System.out.print(a[i] + " ");
System.out.println();
}
public static void main(String[] args)
{
int maxSize = 10;
// initialize the array
int[] a = new int[maxSize];
// fill the array with random elements
for(int j = 0; j < maxSize; j++)
{
int n = (int)( java.lang.Math.random()*(maxSize-1) );
a[j] = n;
}
// sort array
bubble_sort( a );
System.out.print("Sorted array : ");
display(a);
System.out.println(" Maximum Value : " + a[ a.length - 1 ]);
System.out.println(" Miniimum Value : " + a[ 0 ]);
}
}
A C++ program for sorting an array and finding the maximum and minimum elements in the end. Also, the parameter passing method should be call by REFERENCE.
Please Help.
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