Memory Layout for a Matrix class Matrix { double ** contents; int numRows, numCols; … } to initialize: contents = new double * [numRows]; for(int i=0;i<numRows;i++) contents[i] = new double[numCols] contents numRows numCols contents[0] contents[1] contents[0][0]contents[1][2] double **double *double
Naïve Vector Copy class Vector { double * contents; int length; … } contents contents[0] double * 0xFF Vector f() { Vector v(3); // … return v; } Vector v 0xFF2 Copy of Vector v
Copy Constructor class Vector { double * contents; int length; … } contents contents[0] double * 0xF Vector::Vector(const Vector & init) { length = init.length; contents = new double[length]; assert(contents != 0); for (int i = 0; i < length; i++) contents[i] = init.contents[i]; } Vector v 0xFF6 Copy of Vector v
Bubble Sort (1 st Pass) Original Array, Sort Ascending Compare Compare & swap Compare Compare & swap Compare & swap Compare & swap End of 1st pass
Bubble Sort (2 nd Pass) Compare & swap Compare Compare & swap Compare & swap Compare Compare End of 2 nd pass Make up to n passes, or until no swap in a pass.