Reverse array
-
Hi. I got one dimensional array with integer numbers in it. I want to reverse the numbers. The fisrt number should be last and last should be first e.g. [1,2,3,4,5,6,7,8,9] reverse to [9,8,7,6,5,4,3,2,1]. How can I do it fast? Regards.
-
Hi. I got one dimensional array with integer numbers in it. I want to reverse the numbers. The fisrt number should be last and last should be first e.g. [1,2,3,4,5,6,7,8,9] reverse to [9,8,7,6,5,4,3,2,1]. How can I do it fast? Regards.
With STL it's simple:
#include <algorithm>
...
int array[]={1,2,3,4,5,6,7,8,9};
...
std::reverse(array,array+9);Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
With STL it's simple:
#include <algorithm>
...
int array[]={1,2,3,4,5,6,7,8,9};
...
std::reverse(array,array+9);Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi. The fastest way to 'reverse' the array, would be to traverse it backwards. This requires no copying. James.
-
Hi. The fastest way to 'reverse' the array, would be to traverse it backwards. This requires no copying. James.
Thanks!