Skip to content

Commit fe228bf

Browse files
Add files via upload
1 parent ed51667 commit fe228bf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

44_reverseStringRecursion.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
void reverseString(string& str, int start, int end){
5+
//base case
6+
if(start>end){
7+
return;
8+
}
9+
10+
swap(str[start++],str[end--]);
11+
reverseString(str,start,end);
12+
}
13+
int main(){
14+
// Here in this, we are going to reverse the string using recursion
15+
string str;
16+
cout<<"Enter the string to reverse: ";
17+
getline(cin,str);
18+
cout<<endl<<endl;
19+
cout<<"Original String is: "<<str<<endl;
20+
reverseString(str,0,str.length()-1);
21+
cout<<"Reverse String is: "<<str<<endl;
22+
23+
return 0;
24+
}

44_reverseStringRecursion.exe

48 KB
Binary file not shown.

0 commit comments

Comments
 (0)