added left-rotation.cpp file (#84)
* added left-rotation.cpp file * Update README.md Added a link for left-rotation.cpppull/93/head^2
parent
7eb8b8327c
commit
1018546897
|
@ -1,18 +1,19 @@
|
||||||
# Algorithms related to arrays
|
# Algorithms related to arrays
|
||||||
|
|
||||||
### C or C++
|
### C or C++
|
||||||
|
|
||||||
1. [Counting Inversions](c-or-cpp/count-inversions.cpp)
|
1. [Counting Inversions](c-or-cpp/count-inversions.cpp)
|
||||||
2. [Dutch Flag Algo](c-or-cpp/dutch-flag-algo.cpp)
|
2. [Dutch Flag Algo](c-or-cpp/dutch-flag-algo.cpp)
|
||||||
|
3. [Left Rotation of Array](c-or-cpp/left-rotation.cpp)
|
||||||
### Python
|
|
||||||
|
### Python
|
||||||
1. [Counting Inversions](python/count-inversions.py)
|
|
||||||
|
1. [Counting Inversions](python/count-inversions.py)
|
||||||
### JavaScript
|
|
||||||
|
### JavaScript
|
||||||
1. [Counting Inversions](js/count-inversions.js)
|
|
||||||
|
1. [Counting Inversions](js/count-inversions.js)
|
||||||
### Java
|
|
||||||
|
### Java
|
||||||
1. [Counting Inversions](java/count-inversions.java)
|
|
||||||
|
1. [Counting Inversions](java/count-inversions.java)
|
||||||
|
|
|
@ -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]<<" ";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue