Created
May 4, 2014 06:51
-
-
Save jitsceait/07cfe1cc475893b0644b to your computer and use it in GitHub Desktop.
Program to rotate an array at a pivot
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 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