Column ordering for two-dimensional arrays

Source: Internet
Author: User

#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&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.