+ 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]
1 Odpowiedź
+ 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;
}