Created
September 21, 2015 16:34
-
-
Save wicksome/ed77c96af6b38970bf93 to your computer and use it in GitHub Desktop.
LeftRotate
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
| #include<stdio.h> | |
| void printArray(int* arr); | |
| void LeftRotate(int* arr, int size, int n); | |
| int main(void) { | |
| int arr[4] = {1, 2, 3, 4}; | |
| printArray(arr); | |
| LeftRotate(arr,4,2); | |
| printArray(arr); | |
| LeftRotate(arr,4,1); | |
| printArray(arr); | |
| return 0; | |
| } | |
| void LeftRotate(int* arr, int size, int n) { | |
| int temp; | |
| int i; | |
| int r; // rotate | |
| for(r = 0; r < n; r++) { | |
| temp = arr[0]; | |
| for(i = 1; i < n*4; i++) { | |
| arr[i-1] = arr[i]; | |
| } | |
| arr[size-1] = temp; | |
| } | |
| } | |
| void printArray(int* arr) { | |
| int i; | |
| for(i = 0; i < sizeof(arr); i++) { | |
| printf("%d ", arr[i]); | |
| } | |
| printf("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment