Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A \'array palindrome\' is an array which, when its elements are reversed, remain

ID: 3658934 • Letter: A

Question

A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are same when scanned forward or backward) Write a recursive, bool-valued function, isPalindrome, that accepts an integer-valued array, and the number of elements and returns whether the array is a palindrome. An array is a palindrome if: the array is empty (0 elements) or contains only one element (which therefore is the same when reversed), or the first and last elements of the array are the same, and the rest of the array (i.e., the second through next-to-last elements) form a palindrome.

Explanation / Answer

bool is Palindrome(int a[],int number) { if( number== 0 || number == 1) { return true; } else if(a[0] != a[number-1] ) return false; else return is Palindrome( ++a, number - 2 ); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote