here array is passed by value or passed by reference?
As I sort the array in descending order using selection sort and then I called the bubble sort function for sorting the array in ascending order, the output of bubble sort I get is wrong
Type of function arguments
Please send your code so that i can check
How to share the link from coding blocks ide,as there is no link showing on that?
#include
using namespace std;
void selection_sort(int a[], int size)
{
int minindex;
for(int i=0;i<size-1;i++)
{
minindex=i;
for(int j=i+1;j<size;j++)
{
if(a[minindex]<a[j])
minindex=j;
}
int temp=a[i];
a[i]=a[minindex];
a[minindex]=temp;
}
cout<<"the sorted array is "<<endl;
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
cout<<endl;
}
void bubble_sort(int a[],int n)
{
int i;
cout<<"the sorted array is"<<endl;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(a[j+1]<a[j])
{
swap(a[j],a[j+1]);
}
}
for( i=0;i<n;i++)
cout<<a[i]<<" ";
}
}
int main()
{
int a[1000],n;
cout<<“enter the no of elements in the array”<<endl;
cin>>n;
cout<<“enter the elements in the array”<<endl;
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"the unsorted array is"<<endl;
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
selection_sort(a,n);
bubble_sort(a,n);
}
it is passed by reference.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.