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.

Respuesta :

Answer:

Following are the function of  array palindrome

bool ischeckPalindrome(int a1[],int n)  // function definition

{

if( n== 0 || n == 1)  // check the condition

{

return true;  // returns true

}

else

if(a1[0] != a[n-1] ) // check condition

return false;  //return false

else

return ischeckPalindrome( ++a1, n - 2 ); //  portion of the array

}

Explanation:

Following are the description of function .

  • We declared the bool type function bool ischeckPalindrome(int a1[],int n)  it returns true or false or any integer value .In this function we pass the array "a1[]", and the size of array i.e "n".
  • In this we check the condition according to the need the if( n== 0 || n == 1)   check the condition of array size 0 or 1 .If it executed it returns true .
  • If this condition is not executed the control goes to the else block .In this else we have used inner if -else statement .
  • The if(a1[0] != a[n-1]  ) verify the condition if array index 0 is not equal a[n-1] then it returns false other it returns the portion of the array.
  • Finally this function check the palindrome condition .
ACCESS MORE