在二维数组中查找有无此数(非又一次排序)

在一个行列依此增大的二维数组中。最快推断数组中有无此数。


#include<iostream>
using namespace std;

#define ROW  4
#define COLUMN  3
typedef int Shuzu[ROW][COLUMN];  
#define   ElementType int

bool Find(int *matrix,int rows,int columns,int number)
{
	bool found = false;
	if(matrix != NULL && rows >0 && columns>0)
	{
		int row = 0;
		int column = columns - 1;
		while(row < rows && column >=0)
		{
			if(matrix[row * columns + column]==number)
			{
				found = true;
				break;
			}
			else if(matrix[row * columns + column]>number)
				--column;
			else 
				++row;

		}
		
	}
	    cout<<found<<endl;
		return found;
}

void  main()
{
	Shuzu  sh = {1,2,3,2,4,9,3,8,11,5,12,15};
	 
    Find(*sh,ROW,COLUMN,3);
  
}


原文地址:https://www.cnblogs.com/mthoutai/p/6943850.html