Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- void sort(int **mas, int rows, int cols);
- void DeleteArr(int **mas, int rows);
- int main()
- {
- setlocale(LC_ALL, "rus"); // для кирилицы
- int rows = 0; // строки
- int cols = 0; // столбцы
- cout << "Ввести размер строки: "; cin >> rows;
- cout << "Ввести размер столбика: "; cin >> cols;
- int **arr = new int *[rows];
- for (int i = 0; i < rows; i++)
- {
- arr[i] = new int[cols];
- }
- cout << "Заполнить массив из " << rows << " строк " << cols << " столбцов\n";
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- cin >> arr[i][j];
- }
- }
- for (size_t i = 1; i <= cols; i++) //для сортировки по всем столбикам
- {
- sort(arr, rows, i);
- }
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- cout << arr[i][j] << '\t';
- }
- cout << endl;
- }
- DeleteArr(arr, rows);
- system("pause");
- }
- void sort(int **mas, int rows, int NumCol)
- {
- int temp = 0;
- NumCol--;
- for (int a = 1; a < rows; a++)
- {
- for (int b = rows - 1; b >= a; b--)
- {
- while (mas[b - 1][NumCol]>mas[b][NumCol])
- {
- temp = mas[b - 1][NumCol];
- mas[b - 1][NumCol] = mas[b][NumCol];
- mas[b][NumCol] = temp;
- }
- }
- }
- }
- void DeleteArr(int **mas, int rows)
- {
- for (int i = 0; i < rows; i++)
- {
- delete[] mas[i];
- }
- delete[] mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement