Download presentation
Presentation is loading. Please wait.
1
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
2
Naïve Vector Copy class Vector { double * contents; int length; … } contents contents[0] double * 0xFF2 3.10-2 Vector f() { Vector v(3); // … return v; } Vector v 0xFF2 Copy of Vector v
3
Copy Constructor class Vector { double * contents; int length; … } contents contents[0] double * 0xF42 3.10-2 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 3.10-2
4
Bubble Sort (1 st Pass) 61251671114 Original Array, Sort Ascending 61251671114 61251671114 65121671114 Compare Compare & swap Compare 65121671114 Compare & swap 65127161114 Compare & swap 65127111614 Compare & swap 65127111416 End of 1st pass
5
Bubble Sort (2 nd Pass) 65127111416 56127111416 56127111416 Compare & swap Compare Compare & swap 65712111416 Compare & swap 56711121416 Compare 56711121416 Compare 56711121416 End of 2 nd pass Make up to n passes, or until no swap in a pass.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.