FR 2015 #3

go back

Part A

public int getValueAt(int row, int col) { for (SparseArrayEntry e : entries) if (e.getRow() == row && e.getCol() == col) return e.getValue(); return 0; }

Part B

public void removeColumn(int col) { int i = 0; while (i < entries.size()) { SparseArrayEntry e = entries.get(i); int c = e.getCol(); if (c == col) entries.remove(i); else { if (c > col) entries.set(i, new SparseArrayEntry(e.getRow(), c-1, e.getValue())); i++; } } numCols--; }