Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <iomanip>
- //В файле содержится двумерный массив размерностью 𝑛 × 𝑛. В новый файл вывести отсортированный массив
- using namespace std;
- //Столбцы по убыванию помощью гномьей сортировки
- void gnomeSort(int **a, int n, int j)
- {
- int i = 0;
- while(i < n)
- {
- if(i == 0 || a[i - 1][j] >= a[i][j])
- ++i;
- else
- {
- swap(a[i - 1][j], a[i][j]);
- --i;
- }
- }
- }
- int main()
- {
- ifstream in("in.txt");
- ofstream out("out.txt");
- int n;
- cout << "Enter array's dimension: ";
- cin >> n;
- int** a = new int*[n];
- for(int i = 0; i < n; i++)
- {
- a[i] = new int[n];
- for(int j = 0; j < n; j++)
- {
- in >> a[i][j];
- }
- }
- for(int j = 0; j < n; j++)
- {
- gnomeSort(a, n, j);
- }
- for(int i = 0; i < n; i++, out << endl)
- {
- for(int j = 0; j < n; j++)
- {
- out << a[i][j] << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement