Use an optional pair of array indices, so failure is distinct from every valid position:
def search(f: Array[Array[Int]], x: Int): Option[(Int, Int)]
Some((i,j)) denotes a match; None denotes absence. The extra array argument makes the dependence on the searched data explicit; if f is already enclosed in the surrounding scope, it can instead be omitted. For all implementations below, assume f is non-null, its rows are non-null and rectangular, and it remains unchanged during the search. Empty dimensions are permitted.

Articles by others on the same topic (0)

There are currently no matching articles.