Question: #include void Swap ( int * pa , int * pb ) { int tmp = * pa; * pa = * pb; * pb

#include
void Swap(int *pa, int *pb){
int tmp =*pa;
*pa =*pb;
*pb = tmp;
}
void PrintArray(int *ptr, int n){
for (int i =0; i < n; i++){
printf("%d ", ptr[i]);
}
printf("
");
}
int IsLess(int a, int b){
return a < b;
}
int IsLarger(int a, int b){
return a > b;
}
// Define a function pointer type, which points to a function
typedef int (*ComparatorFuncPtr)(int, int);
void BubbleSort(int *ptr, int n, ComparatorFuncPtr compare){
for (int iMax = n -2; iMax >=0; iMax--){
for (int i =0; ____Q1_____; _____Q2____){
if (_____Q3_____){
____Q4____;
}
}
}
}
int main(void){
int arr[]={30,50,20,10,60,40};
int len = sizeof(arr)/ sizeof(arr[0]);
// a function pointer variable which points to the function IsLarger
ComparatorFuncPtr fptr = &IsLarger;
printf("Before sorting:
");
PrintArray(arr, len);
BubbleSort(arr, len, fptr);
// in an ascending order
printf("After sorting:
");
PrintArray(arr, len);
// a function pointer variable which points to the function IsLess
fptr =____Q5____;
printf("
Before sorting:
");
PrintArray(arr, len);
BubbleSort(arr, len, fptr);
// in an descending order
printf("After sorting:
");
PrintArray(arr, len);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!