Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<chrono>
- int main()
- {
- srand(time(0));
- const int ROW = 3;
- const int COLL = 5;
- int arr[ROW][COLL]{};
- for (int i = 0; i < ROW; i++)
- {
- for (int j = 0; j < COLL; j++)
- {
- arr[i][j] = rand() % 30 + 1;
- std::cout << arr[i][j] << " ";
- }
- }
- std::cout << "\n\nAfter sorting\n\n";
- bool sort = false;
- while (!sort)
- {
- sort = true;
- int i = 0, j = 0;
- for (int inext = 0; inext < ROW; inext++)
- {
- for (int jnext = (inext ? 0 : 1); jnext < COLL; jnext++)
- {
- if (arr[i][j] > arr[inext][jnext])
- {
- int tmp = arr[i][j];
- arr[i][j] = arr[inext][jnext];
- arr[inext][jnext] = tmp;
- sort = false;
- }
- i = inext;
- j = jnext;
- }
- }
- }
- for (int i = 0; i < ROW; i++)
- {
- for (int j = 0; j < COLL; j++)
- {
- std::cout << arr[i][j] << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement