It's the shortest and simplest way to write in C++.
#include <algorithm>
std::reverse(str.begin(), str.end());
Use the variable intc
temporarily to exchange the front and back values, as in swapping.
void reverse(char s[])
{
int length = strlen(s) ;
int c, i, j;
for (i = 0, j = length - 1; i < j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
© 2024 OneMinuteCode. All rights reserved.