viewing paste isPalindrome | C++

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream>
#include <cstring>
 
 
bool isPalindrome(const char* s, int low, int high){
    
    if(high <= low)
        return true;
    if(s[low] != s[high])
        return false;
    return isPalindrome(s,low+1,high-1);
    
}
 
int main () {
    
    char* cstring = {"otto"};
    std::cout << (isPalindrome(cstring,0,strlen(cstring)-1) ? "True" : "False");
    
    return 0;
}
 
Viewed 1353 times, submitted by Streusel.