Другие языки программирования и технологии

Функции и указатели подскажите

Вот прога подскажите как привязать ...
Мои ответы - функции указатели
Сортировка Пузырьком по возрастанию и по убыванию с помощью указателя на функцию.

#include <iostream>
using namespace std;
typedef int (*ptr)(const int, const int);
int increase(const int, const int);
int decrease(const int, const int);
void bubble(int *, const size_t, ptr);
void show(const int *, const size_t);
int main() {
    int vector[] = { 3,5,4,2,6,8,1,9,7 };
    size_t size = sizeof(vector) / sizeof(int);
    show(vector, size);
    bubble(vector, size, increase);
    show(vector, size);
    bubble(vector, size, decrease);
    show(vector, size);
    cin.get(); cin.get();
    return 0;
}
void show(const int * _vector, const size_t _size) {
    for (rsize_t n = 0; n < _size; n++) cout << _vector[n] << ' ';
    cout << endl;
}
int increase(const int _a, const int _b) { return _a >= _b; }
int decrease(const int _a, const int _b) { return _a <= _b; }
void bubble(int * _vector, const size_t _size, ptr _cmp) {
    int temp;
    for (rsize_t n = 1; n < _size; n++) {
        for (rsize_t m = 0; m < _size - n; m++) {
            if ((*_cmp)(_vector[m], _vector[m + 1])) {
                temp = _vector[m];
                _vector[m] = _vector[m + 1];
                _vector[m + 1] = temp;
            }
        }
    }
}
Андрей Гец
Андрей Гец
74 443
Лучший ответ
Твоя func4 - массив функций из трех элементов. Присваивать нужно поэлементно, от нулевого элемента до второго. Соответственно, должно быть объявлено три функции, наподобие f4.
Вадим Куркин
Вадим Куркин
63 771