#include<iostream>
#include<string>
void getTheNum(int num,int data[4][4]){
int i=0,j=3;
while(i<4&&j>-1){
if(data[i][j]==num){
std::cout<<i<<" "<<j<<std::endl;
return;
}
else if(data[i][j]<num){
i++;
}
else{
j--;
}
}
std::cout<<"do'nt have this num"<<std::endl;
}
void main(){
int data[4][4]={{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
std::cout<<data[3][0]<<std::endl;
getTheNum(0,data);
system("pause");
}
剑指offer,二维数组中的查找,38页例子代码
最新推荐文章于 2022-03-07 11:44:21 发布