Skip to content

Instantly share code, notes, and snippets.

@bhnascar
Created May 3, 2016 05:00
Show Gist options
  • Save bhnascar/86f716eca9c3e3242d5f9574a3aa43ae to your computer and use it in GitHub Desktop.
Save bhnascar/86f716eca9c3e3242d5f9574a3aa43ae to your computer and use it in GitHub Desktop.
2015 #3 part b
public void removeCol(int col) {
for (int i = entries.size() - 1; i >= 0; i--) {
SparseArrayEntry entry = entries.get(i);
if (entry.getCol() > col) {
// Fix the column number for this item because it's in a column
// to the right of the column we're removing
SparseArrayEntry fixedEntry = new SparseArrayEntry(entry.getRow(),
entry.getCol() - 1,
entry.getValue());
entries.set(i, fixedEntry);
}
else if (entry.getCol() == col) {
// Remove this item because it's inside the column we're removing
entries.remove(i);
}
}
// Update the numCols variable since we removed one column.
numCols--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment