MCPcopy Index your code
hub / github.com/careercup/ctci / partitionAndSearch

Method partitionAndSearch

java/Chapter 11/Question11_6/QuestionB.java:6–17  ·  view source on GitHub ↗
(int[][] matrix, Coordinate origin, Coordinate dest, Coordinate pivot, int elem)

Source from the content-addressed store, hash-verified

4public 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)) {

Callers 1

findElementMethod · 0.95

Calls 1

findElementMethod · 0.95

Tested by

no test coverage detected