Created
January 3, 2011 21:44
-
-
Save nopcoder/764019 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void reverse_r(char* s, int a, int b) { | |
if (a < b) { | |
char tmp = s[a]; | |
s[a] = s[b]; | |
s[b] = tmp; | |
reverse_r(s, a+1, b-1); | |
} | |
} | |
void reverse(char s[]) { | |
int a = 0; | |
int b = strlen(s) - 1; | |
reverse_r(s, a, b); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
char myname[] = "karab"; | |
cout << "Before: " << myname << endl; | |
reverse(myname); | |
cout << "After: " << myname << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment