Skip to content

Instantly share code, notes, and snippets.

@jitsceait
Created May 4, 2014 06:51
Show Gist options
  • Select an option

  • Save jitsceait/07cfe1cc475893b0644b to your computer and use it in GitHub Desktop.

Select an option

Save jitsceait/07cfe1cc475893b0644b to your computer and use it in GitHub Desktop.
Program to rotate an array at a pivot
void reverse_array(int a[], int start, int end){
while(start < end){
int temp = a[start];
a[start] = a[end];
a[end] = temp;
start++;
end--;
}
}
void rotate_array(int a[], int pivot, int len){
int i;
/*Reverse the whole array */
reverse_array(a, 0, len);
/* Reverse from 0 to pivot and pivot to end */
reverse_array(a,0, pivot);
reverse_array(a,pivot+1,len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment