(int[][] matrix, Coordinate origin, Coordinate dest, Coordinate pivot, int elem)
| 4 | public class QuestionB { |
| 5 | |
| 6 | public static Coordinate partitionAndSearch(int[][] matrix, Coordinate origin, Coordinate dest, Coordinate pivot, int elem) { |
| 7 | Coordinate lowerLeftOrigin = new Coordinate(pivot.row, origin.column); |
| 8 | Coordinate lowerLeftDest = new Coordinate(dest.row, pivot.column - 1); |
| 9 | Coordinate upperRightOrigin = new Coordinate(origin.row, pivot.column); |
| 10 | Coordinate upperRightDest = new Coordinate(pivot.row - 1, dest.column); |
| 11 | |
| 12 | Coordinate lowerLeft = findElement(matrix, lowerLeftOrigin, lowerLeftDest, elem); |
| 13 | if (lowerLeft == null) { |
| 14 | return findElement(matrix, upperRightOrigin, upperRightDest, elem); |
| 15 | } |
| 16 | return lowerLeft; |
| 17 | } |
| 18 | |
| 19 | public static Coordinate findElement(int[][] matrix, Coordinate origin, Coordinate dest, int x) { |
| 20 | if (!origin.inbounds(matrix) || !dest.inbounds(matrix)) { |
no test coverage detected