import java.util.ArrayList; /* An instance of this class has a "resident" two-dimensional matrix of ** integer values, provided at construction. In each row of the matrix, ** as well as each column, the values must be in increasing order (with ** no duplicates in any row or column). One can search, with respect ** to a given key, to find all the locations at which it occurs. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: May 2022 */ public class SaddleBackBinSearcher extends SaddleBackSearcher { // constructor // ----------- /* Establishes the resident matrix of this RecSaddleBackSearcher. ** It is verified that the values in the matrix increase along each ** row and column. If not, an IllegalArgumentException is thrown. */ public SaddleBackBinSearcher(int[][] ary) { super(ary); } // private methods // --------------- /* Adds to the ArrayList 'locList' (an inherited instance variable) all ** the locations that contain the search key (inherited instance variable ** 'key') within the specified rectangular region of the resident matrix. */ protected void findAllAux(GridLocation lowCorner, GridLocation highCorner) { if (isEmptyRegion(lowCorner, highCorner)) { // do nothing, as an empty region contains no occurrences of the key } else { // MISSING CODE } } /* Reports whether the rectangular region described by the given corner ** locations is empty. */ private boolean isEmptyRegion(GridLocation lowCorner, GridLocation highCorner) { return lowCorner.ROW > highCorner.ROW || lowCorner.COL > highCorner.COL; } /* Returns the lowest-numbered location within a[low..high] containing ** a value that is >= the given key, or high+1 if no such location exists. ** pre: low <= high+1 and values in a[low..high] are in ascending order. */ private int binarySearch(int[] a, int low, int high, int key) { int left = low; int right = high+1; //loop invariant: values in a[low..left) are < key && // values in a[right..high] are >= key while (left != right) { probeCntr++; int mid = (left + right) / 2; if (a[mid] < key) { left = mid+1; } else { // a[mid] >= key) { right = mid; } } return left; } }