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: 3931005 • 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, boolean -valued  method , isPalindrome, that accepts an integer -valued  array , and a pair of integers representing the starting and ending indexes of the portion of the array to be tested for being a palindrome. The function returns whether that portion of 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

Here is the C++ code for you:

bool isPalindrome(int array[], int start, int end)
{
if(start >= end)
return true;
if(array[start] == array[end])
return isPalindrome(array, start+1, end-1);
else
return false;
}

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