tags:

views:

77

answers:

3

i am trying to get a 2d array in to a form so i can work with it how i need to, i just cant modify it correctly

say i have a 2d array

0 1 0 1 0 
0 0 1 1 1 
0 0 0 3 0 
0 0 0 0 1 
0 0 0 0 0

how can i flip it to its symetrical, so at the moment postition 0,1 is 1 and therfore position 1,0 would be 1?

does this make sence?

i need to do this so i can work out euleurs tour

+1  A: 

You could just access it in a flipped way.

x = 3;
y = 5;

// Ask for x,y element
$normal = $myarray[$x][$y];         

// Ask for x,y in the flipped array by asking for y,x
$flipped_access = $myarray[$y][$x];
rikh
i need a fully symmetircal matrix, this is the problem here, otherwise i would definatley use this solution
timmy
A: 

Something like this (pseudo code)?

for x = 0 to width
  for y = 0 to x-1
     swap( array[x][y], array[y][x] )

Although depending on what your environment is, there might be special methods to do just that.

Steffen
A: 
bhups