For example I have 2×2 matrix, now i have to increase its left and right side to 1 column each, then top and bottom side to 1 row each, now I will have a 4×4 matrix with the old matrix is located in the center of the new one. Is there any way to do it fast rather than create new one and transfer values from old to new one?
Thank you very much
For example I have 2×2 matrix, now i have to increase its left and
Share
You will always have to allocate new memory for the new array, no matter what you do.
Also, if your matrix is only 2×2, the speed of any approach is good enough. Or do you want to handle larger matrices as well? Then, consider the following tests of two methods you can use: