diff --git a/Recursion/palindrome-recursion.cpp b/Recursion/palindrome-recursion.cpp new file mode 100644 index 0000000..335cbad --- /dev/null +++ b/Recursion/palindrome-recursion.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +class Solution { + + public: + + int sumofDigit(int N){ + + int sum=0; + + int temp=N; + + while(temp!=0){ + + int x=temp%10; + + sum+=x; + + temp=temp/10; + + } + + return sum; + + } + + int intToString(int N){ + + string convertdNum=to_string(N); + + string reverseString=convertdNum; + + reverse(reverseString.begin(),reverseString.end()); + + return reverseString==convertdNum ? 1 : 0; + + } + + int isDigitSumPalindrome(int N) { + + // code here + + int ans=sumofDigit(N); + + intToString(ans); + + } + +}; \ No newline at end of file diff --git a/Recursion/reverse-stack-recursion.cpp b/Recursion/reverse-stack-recursion.cpp new file mode 100644 index 0000000..cd23204 --- /dev/null +++ b/Recursion/reverse-stack-recursion.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +class Solution{ +public: + stack solve(stack &St , stack &answer){ + + if(St.empty()){ + + return answer ; + + } + int element = St.top() ; + + answer.push(element) ; + + St.pop() ; + + solve(St , answer) ; + + return answer ; + } + + void Reverse(stack &St){ + stack answer ; + St = solve(St , answer) ; + } +}; \ No newline at end of file