Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication2
- {
- class Program
- {
- //Function to reverse arr[] from index start to end
- static void reverseArray(int[] arr, int start, int end)
- {
- int i;
- int temp;
- while (start < end)
- {
- temp = arr[start];
- arr[start] = arr[end];
- arr[end] = temp;
- start++;
- end--;
- }
- }
- //Function to left rotate arr[] of size n by d
- static void leftRotate(int[] arr, int d, int n)
- {
- reverseArray(arr, 0, d - 1);
- reverseArray(arr, d, n - 1);
- reverseArray(arr, 0, n - 1);
- }
- // Function to print an array
- static void printArray(int[] arr, int size)
- {
- int i;
- for (i = 0; i < size; i++)
- Console.WriteLine(arr[i]);
- }
- //Driver program to test above functions
- static void Main(string[] args)
- {
- int[] arr = new[] { 4, 8, 15, 16, 23, 42, 99 };
- leftRotate(arr, 3, 7);
- printArray(arr, 7);
- }
- }
- }
- // Found on Internet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement