-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy path3Left-Right-Rotation.cpp
More file actions
51 lines (50 loc) · 1.17 KB
/
Copy path3Left-Right-Rotation.cpp
File metadata and controls
51 lines (50 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 3 // Left Rotation and Right Rotation of a string.
#include<iostream>
using namespace std;
int main()
{
string Lrot, Rrot;
int Rotate;
char temp;
cout << "\nEnter a string : ";
getline(cin, Lrot);
Rrot = Lrot;
cout << "\nHow many times u want to rotate : ";
cin >> Rotate;
int n = Rrot.size()-1;
for(int i=0; i<Rotate; i++)
{
for(int j=0; j<Lrot.size(); j++)
{
if(j==0)
{
temp = Lrot[j];
}
else
{
Lrot[j-1] = Lrot[j];
if(j == Lrot.size()-1)
{
Lrot[j] = temp;
}
}
}
for(int k=n; k>=0; k--)
{
if(k==Rrot.size()-1)
{
temp = Rrot[k];
}
else
{
Rrot[k+1] = Rrot[k];
if(k == 0)
{
Rrot[k] = temp;
}
}
}
}
cout << "\nLeft Rotation : " << Lrot;
cout << "\n\nRight Rotation : " << Rrot << "\n\n";
}