Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. void sort(int **mas, int rows, int cols);
  7. void DeleteArr(int **mas, int rows);
  8.  
  9.  
  10. int main()
  11. {
  12. setlocale(LC_ALL, "rus"); // для кирилицы
  13.  
  14. int rows = 0; // строки
  15. int cols = 0; // столбцы
  16.  
  17. cout << "Ввести размер строки: "; cin >> rows;
  18. cout << "Ввести размер столбика: "; cin >> cols;
  19.  
  20. int **arr = new int *[rows];
  21.  
  22. for (int i = 0; i < rows; i++)
  23. {
  24. arr[i] = new int[cols];
  25. }
  26.  
  27. cout << "Заполнить массив из " << rows << " строк " << cols << " столбцов\n";
  28.  
  29. for (int i = 0; i < rows; i++)
  30. {
  31. for (int j = 0; j < cols; j++)
  32. {
  33. cin >> arr[i][j];
  34. }
  35. }
  36.  
  37. for (size_t i = 1; i <= cols; i++) //для сортировки по всем столбикам
  38. {
  39. sort(arr, rows, i);
  40. }
  41.  
  42. for (int i = 0; i < rows; i++)
  43. {
  44. for (int j = 0; j < cols; j++)
  45. {
  46. cout << arr[i][j] << '\t';
  47. }
  48. cout << endl;
  49. }
  50.  
  51. DeleteArr(arr, rows);
  52. system("pause");
  53. }
  54.  
  55.  
  56. void sort(int **mas, int rows, int NumCol)
  57. {
  58. int temp = 0;
  59. NumCol--;
  60.  
  61. for (int a = 1; a < rows; a++)
  62. {
  63. for (int b = rows - 1; b >= a; b--)
  64. {
  65. while (mas[b - 1][NumCol]>mas[b][NumCol])
  66. {
  67. temp = mas[b - 1][NumCol];
  68. mas[b - 1][NumCol] = mas[b][NumCol];
  69. mas[b][NumCol] = temp;
  70. }
  71. }
  72. }
  73. }
  74.  
  75. void DeleteArr(int **mas, int rows)
  76. {
  77. for (int i = 0; i < rows; i++)
  78. {
  79. delete[] mas[i];
  80. }
  81. delete[] mas;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement