added left-rotation.cpp file (#84)

* added left-rotation.cpp file

* Update README.md

Added a link for left-rotation.cpp
pull/93/head^2
B PAVAN KUMAR 2021-03-01 00:54:22 +05:30 committed by GitHub
parent 7eb8b8327c
commit 1018546897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 18 deletions

View File

@ -1,18 +1,19 @@
# Algorithms related to arrays
### C or C++
1. [Counting Inversions](c-or-cpp/count-inversions.cpp)
2. [Dutch Flag Algo](c-or-cpp/dutch-flag-algo.cpp)
### Python
1. [Counting Inversions](python/count-inversions.py)
### JavaScript
1. [Counting Inversions](js/count-inversions.js)
### Java
1. [Counting Inversions](java/count-inversions.java)
# Algorithms related to arrays
### C or C++
1. [Counting Inversions](c-or-cpp/count-inversions.cpp)
2. [Dutch Flag Algo](c-or-cpp/dutch-flag-algo.cpp)
3. [Left Rotation of Array](c-or-cpp/left-rotation.cpp)
### Python
1. [Counting Inversions](python/count-inversions.py)
### JavaScript
1. [Counting Inversions](js/count-inversions.js)
### Java
1. [Counting Inversions](java/count-inversions.java)

View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,left_rotation_val;
cin>>n>>left_rotation_val;
int arr[n];
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
left_rotation_val = left_rotation_val % n;
//Doing this we can get the place from where the rotation starts.
// 5 4
// 1 2 3 4 5
// 1 2 3 4 5 -> 2 3 4 5 1(1 rotation) -> 3 4 5 1 2(2 rotation) -> 4 5 1 2 3(3 rotation) -> 5 1 2 3 4(4 rotation)
for(int i = left_rotation_val; i<n; i++){
cout<<arr[i]<<" ";
}
for(int i = 0;i<left_rotation_val;i++){
cout<<arr[i]<<" ";
}
}