Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void RandArray(int** array, int row, int column)
- {
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < column; j++)
- {
- array[i][j] = 1 + rand() % 50;
- }
- }
- }
- void PrintArray(int** array, int row, int column)
- {
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < column; j++)
- {
- cout << array[i][j] << "\t";
- }
- cout << endl;
- }
- }
- void ExchangeSortArray(int** array, int row, int column)
- {
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < column; j++)
- {
- int m = i;
- int n = j + 1;
- while (true)
- {
- if (n == column)
- {
- n = 0;
- m++;
- if (m == row)
- break;
- }
- if (array[i][j] > array[m][n])
- swap(array[i][j], array[m][n]);
- n++;
- }
- }
- }
- }
- int main()
- {
- int row, column;
- cin>>row;
- cin>>column;
- int** array = new int* [row];
- for (int count = 0; count < row; count++)
- array[count] = new int[column];
- RandArray(array, row, column);
- cout << "Init random array: " << endl;
- PrintArray(array, row, column);
- cout << endl;
- cout << "After sort: " << endl;
- ExchangeSortArray(array, row, column);
- PrintArray(array, row, column);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment