Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #55 from skandhavs/main
Browse files Browse the repository at this point in the history
Finished Left Rotation in C++
  • Loading branch information
ndrohith09 authored Oct 20, 2022
2 parents 0d02f7c + 1edb55b commit 036cfd9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions c++/Left Rotation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
#include <stdio.h>
using namespace std;
void rotateleft(int arr[],int d)
{
int n = (sizeof(arr)/2)+1;
for(int i=0; i<d; i++){
int j, first_val;
first_val = arr[0];
for(j=0;j<n-1;j++){
arr[j] = arr[j+1];
}
arr[j] = first_val;
}
cout<<"Left Rotate by "<<d <<" times gives : ";
for(int i=0; i<n; i++){
cout<<arr[i];
}
}
int main()
{
int n ,d;
cout<<"Enter the number of elements and number of rotations : ";
cin>>n>>d;
int arr[n];
cout<<"Enter the elements of the array : ";
for (int i=0; i<n;i++)
{
cin>>arr[i];
}
rotateleft(arr,d);
return 0;
}

0 comments on commit 036cfd9

Please sign in to comment.