Skip to content

Instantly share code, notes, and snippets.

@talobin
Created April 16, 2014 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talobin/10808064 to your computer and use it in GitHub Desktop.
Save talobin/10808064 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
//this method complexity is O(n) time and O(1) space
void reverse(char *str) {
cout<<str<<endl;
char *end=str;
while(*end)
end++;
end--;
char *start = str;
while (start<end){
char temp = *start;
*start++ = *end;
*end-- = temp;
}
cout <<str<<endl;
}
int main(int argc, const char * argv[])
{
char test[] = "My startup kills";
char *pointer = test;
//pointer++;
//*pointer = 'a';
reverse(pointer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment