二维有序数组找特定数字

给定有序二维数组,向右越来越大,向下越来越大,给定一个特定的数字, 如果在该数组中返回1,否则返回0

分析:

从右上角开始一次向左下逼近,直到找到或者数组遍历一遍

#include<iostream> 
using namespace std;

bool select(int a[4][5], int b){
	int row=0;
	int col=3;
	while(row<=3&&col>=0){
		if(a[row][col]==b){
			return 1;
		}else if(a[row][col]>b){
			col--;
		}else{
			row++;
		}
	}
	return 0;
}


int main(){
	int a[4][5] = {3, 7, 8 ,9, 12, 4, 6 ,10, 12, 15, 6, 9, 11, 13, 17, 8, 19, 15, 17, 20};
	cout<<select(a,17)<<endl;
}