/* Write a short recursive C++ function that determines if a string s is a palindrome, that is, it is equal to its rever

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

/* Write a short recursive C++ function that determines if a string s is a palindrome, that is, it is equal to its rever

Post by answerhappygod »

/*Write a short recursive C++ function that determines if a string sis apalindrome, that is, it is equal to its reverse. For example,"racecar"and "gohangasalamiimalasagnahog" are palindromes.*/#include <iostream>#include <string>bool isPalinHelper(std::string& s, int begin, int end) {// Your code here}bool isPalin(std::string& s) {return isPalinHelper(s, 0, s.size()-1);}int main() {std::string s1{"racecar"}; // Palindromeif (isPalin(s1)) std::cout << s1 << " is a palindrome"<< std::endl;else std::cout << s1 << " is not a palindrome" <<std:: endl;std::string s2{"racecars"}; // Not a palindromeif (isPalin(s2)) std::cout << s2 << " is a palindrome"<< std::endl;else std::cout << s2 << " is not a palindrome" <<std:: endl;std::string s3{"gohangasalamiimalasagnahog"};if (isPalin(s3)) std::cout << s3 << " is a palindrome"<< std::endl;else std::cout << s3 << " is not a palindrome" <<std:: endl;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply