#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include < iostream>using namespace std; #include "oj.h"//function: Arrange an array of m rows n column Size//input: int * Parray Pointer to the first element of the array, M is the number of rows, n is the number of columns, please arrange by column I Output: An array sorted by column I is placed into the address specified by the input parameter (the value range of I 1-n)//return: void Rangearray (int * parray,unsigned int m, unsigned int n,unsigned int i) {BOOL Flag =0;//is used to identify if the next line is smaller than the previous line, if the next line is small, flag is 1, otherwise 0;int temp =0;for (unsigned int row =0; row < m-1; ++row) {flag =0;f or (unsigned int col = i-1; col < n; ++col) {if (Parray[row * n + col] > Parray[row * n + n + col]) {flag = 1;break;} }IF (flag = = 1)//downlink is smaller than the previous line, exchanging two lines of the element {for (unsigned int col1 =0; col1 < n; ++col1) {Temp =parray[row * n + col1];p Array[row * n + col1] =parray[row * n + n + col1];p array[row * n + n + col1] = temp;}}} int main () {int parray[2][4] = {2,3,4,5,3,7,8,10}; Rangearray (&parray[0][0],2,4,1); for (int i =0, i < 2; ++i) {for (int J =0; J < 4; ++j) {COUT<<PARRAY[I][J]&L t;< "";} Cout<<endl;} Int Retarray[4][3] = {1,2,3,2,3,4,2,3,1, 1,3,1}; Rangearray (&retarray[0][0],4,3,2); for (int i =0, i < 4; ++i) {for (int J =0; j < 3; ++j) {cout<<retarray[i][ j]<< "";} Cout<<endl;} return 0;}
Column ordering for two-dimensional arrays