I have an exercise to implement two function ascendingSort, descendingSort and function mySort.
#include<iostream>
#include <math.h>
using namespace std;
void ascendingSort(int a[], int n) {
//TODO
}
void descendingSort(int a[], int n) {
//TODO
}
void mySort(int a[], int n, void (*sort)(int[], int)) {
/*
* STUDENT ANSWER
* TODO: sort array based on sort algorithm of function sort.
*/
}
int main() {
int n = 5;
int a[5] = { 1, 2, 3, 4, 5 };
void (*sortAlgorithm)(int[], int) = descendingSort;
mySort(a, n, sortAlgorithm);
for (int i = 0; i < n; ++i) {
printf("%d ", a[i]);
}
return 0;
}
I can implement two sort function. But I don't know how to write function mySort Can you give me any ideas? Thank you!