二维数组中的查找

bool find(int* data, int rows, int columns, int number)
{
    if (data == nullptr || rows <= 0 || columns <= 0)
        return false;

    bool bfind = false;
    int row = 0;
    int column = columns - 1;
    while (row < rows && column >= 0)
    {
        if (data[row * columns + column] > number)
            --column;
        else if (data[row * columns + column] < number)
            ++row;
        else
        {
            bfind = true;
            break;
        }        
    }

    return bfind;
}

 

posted on 2021-01-21 15:04  Noora&w  阅读(59)  评论(0编辑  收藏  举报