Created
May 1, 2018 15:21
-
-
Save osvein/a136f102e30163cbe28c5d51e313d2b2 to your computer and use it in GitHub Desktop.
O(n) time, O(1) size array rotation
This file contains hidden or 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 | |
rotate(char *first, char *newfirst, char *end) | |
{ | |
char *next; | |
next = newfirst; | |
while (next != first) { | |
char swap; | |
swap = *first; | |
*(first++) = *next; | |
*(next++) = swap; | |
if (next >= end) | |
next = newfirst; | |
else if (first >= newfirst) | |
newfirst = next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment