mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-10 14:09:17 +08:00
rename Operations on Datastructures -> operations_on_datastructures (#655)
This commit is contained in:
39
operations_on_datastructures/Array Left Rotation.cpp
Normal file
39
operations_on_datastructures/Array Left Rotation.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n, k;
|
||||
cout << "Enter size of array=\t";
|
||||
cin >> n;
|
||||
cout << "Enter Number of indeces u want to rotate the array to left=\t";
|
||||
cin >> k;
|
||||
int a[n];
|
||||
cout << "Enter elements of array=\t";
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
int temp = 0;
|
||||
for (int i = 0; i < k; i++)
|
||||
{
|
||||
temp = a[0];
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
if (j == n - 1)
|
||||
{
|
||||
a[n - 1] = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
a[j] = a[j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << "Your rotated array is=\t";
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cout << a[j] << " ";
|
||||
}
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user