Last active
February 4, 2018 16:59
-
-
Save hckim16/17090578459b7075be62407bd6f303f0 to your computer and use it in GitHub Desktop.
left rotation using standard libraries - vector and algorithm
This file contains 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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
vector<int> left_rotate(vector<int>array, int r){ | |
rotate(array.begin(), array.begin()+r, array.end()); | |
return array; | |
} | |
int main(){ | |
int n; | |
int r; | |
cout << "Enter number of integers in array: "; | |
cin >> n; | |
cout << endl; | |
cout << "Enter number of rotations to left: "; | |
cin >> r; | |
cout << endl; | |
vector<int> arr(n); | |
for(int i = 0; i < n; i++){ | |
cout << "Enter integer: "; | |
cin >> arr[i]; | |
} | |
for(int i = 0; i < n; i++){ | |
cout << arr[i] << " "; | |
} | |
cout << endl; | |
vector<int> newArr = left_rotate(arr, r); | |
for(int i = 0; i < n; i++){ | |
cout << newArr[i] << " "; | |
} | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment