Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- СДАТЬ. Задача на сортировки, вторая римская.
- #include <iostream>
- using namespace std;
- void sortChoice(int** array, int n)
- {
- int index1, index2;
- for (int j = 0; j < n; j++)
- {
- for (int i = 0; i < n - 1; i++)
- {
- int min = array[i][j];
- index1 = i;
- index2 = j;
- for (int k = i + 1; k < n; k++)
- if (array[k][j] < min) { min = array[k][j]; index1 = k; index2 = j; }
- swap(array[i][j], array[index1][index2]);
- }
- }
- }
- int main()
- {
- int n;
- cout << "Enter N:"; //вводим размеры матрицы(размеры для массива)
- cin >> n;
- int** array = new int*[n];
- for (int i = 0; i < n; i++)
- array[i] = new int[n];
- cout << "Enter matrix [N x N]:" << endl; //вводим саму матрицу
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- cin >> array[i][j];
- sortChoice(array, n);//сортировка
- cout << "Result:" << endl;
- for (int i = 0; i < n; i++)//вывод результата
- {
- for (int j = 0; j < n; j++)
- {
- cout << array[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment