Last active
June 7, 2018 21:12
-
-
Save patelpreet422/6d0ab4f25d2d499733c4f75f9039a2a6 to your computer and use it in GitHub Desktop.
Palindrome using recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
bool isPalindrome(const string &str, int low, int high) | |
{ | |
if (low >= high)return true; | |
if (str[low] != str[high])return false; | |
return isPalindrome(str, ++low, --high); | |
} | |
bool isPalindrome(const string &str) | |
{ | |
return isPalindrome(str, 0, str.size()-1); | |
} | |
int main() | |
{ | |
cout << boolalpha << isPalindrome("boc") << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment