Skip to content

Instantly share code, notes, and snippets.

@kemingy
Created January 1, 2017 14:19
Show Gist options
  • Save kemingy/778db742ca8b6012b209b811d8fc99b7 to your computer and use it in GitHub Desktop.
Save kemingy/778db742ca8b6012b209b811d8fc99b7 to your computer and use it in GitHub Desktop.
shift strings(use 3 reverse)
void reverse(char* s, int start, int end)
{
char t;
while(start < end)
{
t = s[start];
s[start++] = s[end];
s[end--] = t;
}
// printf("%s\n", s);
}
void shift(char* s, int n, int length)
{
n = n % length;
// printf("--%s %d\n", s, length);
reverse(s, 0, n - 1);
reverse(s, n, length - 1);
reverse(s, 0, length - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment