It is necessary to sort the pyramidal sorting of the array columns in ascending order. There is a code for a one-dimensional array. I just can not figure out how you can remake it under the two-dimensional.

#include "pch.h" #include <iostream> #include <fstream> using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); void heapF(int *number, int i, int n) { int max = i; while (true) { max = i; int child = 2 * i + 1; if (child < n && number[child] > number[max]) max = child; child++; if (child<n && number[child] > number[max]) max = child; if (i == max) break; else { swap(number[i], number[max]); i = max; } } } void piramid(int *array, int N) { for (int i = N / 2; i >= 0; i--) heapF(array, i, N); for (int i = N - 1; i >= 0; i--) { swap(array[i], array[0]); heapF(array, 0, i); } } int main() { int N, i, j; int *matr; in >> N; matr = new int[N]; for (i = 0; i < N; ++i) for (j = 0; j < N; ++j) in >> matr[i]; piramid(matr, N); out << N << endl; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) out << matr[i] << " "; out << endl; } return 0; } 
  • Well, just work with columns? Each column, if I understand correctly, you need to sort separately. Well there and use matr[i][column] ... decide only how exactly you store and transfer the matrix .. - Harry

0