The thinking harvest of the two-dimensional array problem
This algorithm has nothing to do with data structure, it is mainly logical thinking to use the relationship between the data, more examples of concrete attempts to concrete complex problems, analysis of that situation, time complexity is low. Think first, then write the code. Code close to your own thinking.
L code harvesting for two-dimensional array processing
When you treat a two-dimensional array as an argument in C + +, you must indicate all dimension sizes or omit the first dimension. However, when we write the program often encounter each dimension is not fixed, we can not think of it as a two-dimensional array, but instead of it as a normal pointer, in addition to two parameters to indicate the number of dimensions, and then we are two-dimensional array manually addressed, so that the two-dimensional array as a parameter to pass the purpose
#include <iostream>using namespacestd;//The difference between int * Matrix and int matrix[][] when passing parameters;//sometimes recursion makes simple problems more complicated;//Sometimes we write code to define variables to be close to thinking, but also pay attention to the code speed; intFind (int* Matrix,intRowsintColumnsintNumber ) { introw =0, column = Columns-1; while(column>=0&& row<rows) { if(* (matrix+row*columns+column) = =Number ) {cout<<* (Matrix+row*columns+column) <<"Find"<<Endl; return 1; } if(* (Matrix+row*columns+column) < number)//In addition to having a return, be sure to note the If else match{cout<<* (Matrix+row*columns+column) <<"it's small."<<Endl; Row++; }Else{cout<<* (Matrix+row*columns+column) <<"big."<<Endl; Column--; } } return 0; }intMain () {intdata[4][4]= { 1,2,8,9, 2,4,9, A, 4,7,Ten, -, 6,8, One, the }; intnum[4][5] { 1,2,8,9,Ten, 2,4,9, A, -, 4,7,Ten, -, -, 6,8, One, the, - }; cout<<find (& (data[0][0]),4,4,0) <<Endl; cout<<find (& (num[0][0]),4,5, -) <<Endl;}
Two-dimensional arrays are passed as parameters