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