#include
using namespace std;[quote=“khushmanglani31217_7de9bf16f9c8f286, post:1, topic:167789, full:true”]
#include <iostream>
using namespace std;
bool compare(int a,int b){
cout<<"Comparing "<<a<<" and "<<b<<endl;
return a < b;
}
//We will implement our own sort method
void bubble_sort(int arr[],int n, bool (&cmp)(int a,int b)){
//N-1 iteration to move N-1 large element to the end
for(int i=0 ; i < n - 1 ; ++i){
//pairwise swapping in unsorted part
for(int j=0 ; j < n - i - 1; ++j){
if(cmp(arr[j+1],arr[j]))
swap(arr[j+1],arr[j]);
}
}
}
int main(){
int n;
cin>>n;
int a[1000];
//Taking input from the user
for(int i=0 ; i < n ; ++i){
cin>>a[i];
}
bubble_sort(a,n,compare);
for(int i=0 ; i < n ; ++i){
cout<<a[i]<<",";
}
cout<<endl;
return 0;
}
I am not able to understand how we pass function as parameter void bubble_sort(int arr[],int n, bool (&cmp)(int a,int b)) and how we pass this bool (&cmp)(int a,int b) name to compare function.