Skip to content

Instantly share code, notes, and snippets.

@osvein
Created May 1, 2018 15:21
Show Gist options
  • Save osvein/a136f102e30163cbe28c5d51e313d2b2 to your computer and use it in GitHub Desktop.
Save osvein/a136f102e30163cbe28c5d51e313d2b2 to your computer and use it in GitHub Desktop.
O(n) time, O(1) size array rotation
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