¿Como se hace un intercambio de filas en una matriz dinámica? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

¿Como se hace un intercambio de filas en una matriz dinámica?

Por ejemplo, intercambiar la fila [0][0], [0][1], [0][2] con la fila [2][0], [2][1], [2][2]

12th Mar 2019, 3:54 AM
LuisRSA24
LuisRSA24 - avatar
1 Answer
+ 10
Referring to your example you should have something like (with Type being your data type (int, char, float..)): /* having the size of your dynamic array saved together with the pointer to the first element of the array would be better (you can do it by creating a struct) */ const unsigned int size = 3; Type *arr = new Type[size,size]; // some assignment to array elements for(int i=0; i<size; ++i) { Type temp = arr[0,i]; arr[0,i] = arr[2,i]; barr[2,i] = temp; }
29th Mar 2019, 12:30 AM
Andrea Leoni
Andrea Leoni - avatar