如题:
设计算法
bool Find(int *maxtrix, const int rows, const int cols, const int key)
{
if (maxtrix == NULL || rows < 0 || cols < 0) {
return false;
}
bool found = false;
int row = 0, col = cols - 1;
while (row < rows && col >= 0) {
if (maxtrix[row * cols + col] == key) {
found = true;
break;
} else if (maxtrix[row * cols + col] > key) {
-- col;
} else {
++ row;
}
}
return found;
}