Created
January 1, 2017 14:19
-
-
Save kemingy/778db742ca8b6012b209b811d8fc99b7 to your computer and use it in GitHub Desktop.
shift strings(use 3 reverse)
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
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