Skip to content

Commit 6df6dec

Browse files
authored
Add files via upload
1 parent 3834fb3 commit 6df6dec

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

Diff for: Assignment Recursion 1b/Pair Star.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Change in the given string itself. So no need to return or print the changed
2+
// string.
3+
void ftn(char input[], int len) {
4+
if (len == 0)
5+
{
6+
return;
7+
}
8+
9+
if(input[0] == input[1])
10+
{
11+
for (int i = len; i >= 0; i--)
12+
{
13+
input[i + 1] = input[i];
14+
}
15+
input[1] = '*';
16+
ftn(input + 2, len - 1);
17+
}
18+
else
19+
{
20+
ftn(input + 1, len - 1);
21+
}
22+
23+
}
24+
void pairStar(char input[]) {
25+
// Write your code here
26+
27+
int size = 0;
28+
for (int i = 0; input[i] != '\0'; i++) size++;
29+
30+
ftn(input, size);
31+
}

Diff for: Assignment Recursion 1b/Remove X.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Change in the given string itself. So no need to return or print anything
2+
void ftn(char input[], int length) {
3+
if (length == 0)
4+
{
5+
return;
6+
}
7+
8+
if (input[0] == 'x')
9+
{
10+
// shift by 1 place
11+
for (int i = 0; i < length; i++)
12+
{
13+
input[i] = input[i + 1];
14+
}
15+
ftn(input, length-1);
16+
} else {
17+
ftn(input + 1, length - 1);
18+
}
19+
}
20+
void removeX(char input[]) {
21+
// Write your code here
22+
int size = 0;
23+
for (int i = 0; input[i] != '\0'; i++) size++;
24+
25+
ftn(input, size);
26+
}

Diff for: Assignment Recursion 1b/Replace pi (recursive).cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Change in the given string itself. So no need to return or print anything
2+
void ftn(char input[], int length)
3+
{
4+
if(length == 0)
5+
{
6+
return;
7+
}
8+
9+
if(input[0] == 'p' && input[1] == 'i')
10+
{
11+
// shift by 2 place
12+
for(int i=length-1; i>=0; i--)
13+
{
14+
input[i+2] = input[i];
15+
}
16+
//insert 3.14
17+
input[0] = '3';
18+
input[1] = '.';
19+
input[2] = '1';
20+
input[3] = '4';
21+
ftn(input+4, length-2);
22+
}
23+
else
24+
{
25+
ftn(input+1, length-1);
26+
}
27+
}
28+
void replacePi(char input[]) {
29+
// Write your code here
30+
int size = 0;
31+
for(int i=0; input[i]!='\0'; i++) size++;
32+
33+
ftn(input, size);
34+
}

Diff for: Assignment Recursion 1b/String to Integer.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
int ftn(char input[], int len)
2+
{
3+
if(len == 0)
4+
{
5+
return 0;
6+
}
7+
8+
int ans = ftn(input, len-1);
9+
10+
return ans * 10 + (input[len-1] - '0');
11+
}
12+
int stringToNumber(char input[]) {
13+
// Write your code here
14+
15+
int size = 0;
16+
for (int i = 0; input[i] != '\0'; i++)
17+
size++;
18+
19+
int ans = ftn(input, size);
20+
return ans;
21+
}

Diff for: Assignment Recursion 1b/Tower of Hanoi.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
void towerOfHanoi(int n, char source, char auxiliary, char destination) {
2+
// Write your code here
3+
if(n == 0)
4+
{
5+
return;
6+
}
7+
towerOfHanoi(n - 1, source, destination, auxiliary);
8+
cout << source << ' ' << destination << endl;
9+
towerOfHanoi(n - 1, auxiliary, source, destination);
10+
}

0 commit comments

Comments
 (0)