// AP Computer Science, A Exam, 1996, Question 4, part B in C++ // also AB Exam, question 2 void RemoveCross(apmatrix & m, int R, int C) // precondition: 0 <= R < m.numRows(); 0 <= C < m.numCols() // postcondition: row with index R and column with index C // have been removed from m { int j,k; int rows = m.numRows(); // store value, call only once int cols = m.numCols(); / per loop iteration // shift all columns to the left once, // starting with index c for(j=0; j < rows; j++) { for(k=C; k < cols-1; k++) // avoid bad index at right { m[j][k] = m[j][k+1]; // shift left } } // now shift rows "up", matrix is a vector of vectors for(j=R; j < rows-1; j++) // avoid bad index at bottom { m[j] = m[j+1]; // shift up } m.resize(rows-1,cols-1); // resize the matrix }