Reverse a string without editing original string and no extra space and swap functions
Algorithm
Output : Reverse of s (Eg: em ver )
Implementation
Please comment if you find anything incorrect.
Algorithm
- Use recursion to keep moving till end of string.
- Display data in each index of string
Output : Reverse of s (Eg: em ver )
Implementation
#include <iostream> #include <string> using namespace std; void Reverse ( const char * s ) { if ( *s ) { Reverse ( s+1 ) ; cout<<*s; } } int main() { string s; getline ( cin,s ); const char *p= s.c_str(); Reverse ( p ); getchar(); }
No comments:
Post a Comment