class MyArray
{
static void Main(string[] args)
{
int[,] a = new int[3, 3] {
{ 1,2,3},
{ 2,4,5},
{ 5,6,7}
};
bool isfind= find(3, a);
Console.Write(isfind);
}
public static bool find(int target, int[,] arry)
{
int row = arry.GetLength(0);
int col = arry.GetLength(1);
int i, j;
for ( i = row-1,j=0; i >=0&&j<col ; )
{
if (target == arry[i, j])
return true;
if (target < arry[i, j])
{
i--;
continue;
}
if (target > arry[i, j])
{
j++;
continue;
}
}
return false;
}
}
(c#)二维数组的查找
最新推荐文章于 2024-07-11 19:45:30 发布