MCPcopy Create free account
hub / github.com/careercup/ctci / Coordinate

Class Coordinate

java/Chapter 11/Question11_6/Coordinate.java:3–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1package Question11_6;
2
3public class Coordinate implements Cloneable {
4 public int row;
5 public int column;
6 public Coordinate(int r, int c) {
7 row = r;
8 column = c;
9 }
10
11 public boolean inbounds(int[][] matrix) {
12 return row >= 0 &&
13 column >= 0 &&
14 row < matrix.length &&
15 column < matrix[0].length;
16 }
17
18 public boolean isBefore(Coordinate p) {
19 return row <= p.row && column <= p.column;
20 }
21
22 public Object clone() {
23 return new Coordinate(row, column);
24 }
25
26 public void moveDownRight() {
27 row++;
28 column++;
29 }
30
31 public void setToAverage(Coordinate min, Coordinate max) {
32 row = (min.row + max.row) / 2;
33 column = (min.column + max.column) / 2;
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected