Skip to content

Instantly share code, notes, and snippets.

@nopcoder
Created January 3, 2011 21:44
Show Gist options
  • Save nopcoder/764019 to your computer and use it in GitHub Desktop.
Save nopcoder/764019 to your computer and use it in GitHub Desktop.
#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