0

An efficient way Reverse subscripting an array without for(i= 3; i>=0; i--)

I've been making a rubix cube code that does weird array subscripts like circling through an array (x[2],x[1],x[0],x[3]) the code rearranges things forward and back but I don't have a problem going forward because I can just module it. I'm currently getting around it is by making an array that has[2,1,0,3] but since I plan on uploading it onto an Arduino I'm worried about memory issues does anyone know a more efficient way?

14th Mar 2020, 8:38 PM
Stuart Moss
Stuart Moss - avatar
1 Answer
+ 1
I am not sure if I understand your question. But if you just want to reverse an array you can swap the elements. If the array has a fixed size you don't need a loop. a[0], a[1], a[2], a[3] temp = a[0]; a[0] = a[3]; a[3] = temp; temp = a[1]; a[1] = a[2]; a[2] = temp;
15th Mar 2020, 8:46 PM
Denise Roßberg
Denise Roßberg - avatar