Reverse a String
**Reversing a string is the technique that reverses or changes the order of a given string so that the last character of the string becomes the first character of the string and so on. Furthermore, we can also check the Palindrome of the given string by reversing the original string.
For example, we enter a string "APPLE", and then use the reverse algorithm. The reverse algorithm returns the string "ELPPA" which is completely reverse of the original string. **
Different Methods to Reverse a String in C++ are:
-> Making our own reverse function -> Using ‘inbuilt’ reverse function -> Using Constructor -> Using a temp file
C++ program to reverse a string using recursion
#include <iostream>
using namespace std;
void getreverse(string &str, int i)
{
if (i > (str.length() - 1 - i))
{
return;
}
swap(str[i], str[str.length() - i - 1]);
i++;
getreverse(str, i);
}
int main()
{
string name = "APPLE";
getreverse(name, 0);
cout << name << endl;
return 0;
}
Log in or sign up for Devpost to join the conversation.