0
How can you check if the elements in an array are palindromic using C++?
I have seen several methods that use cin input for the string but I have to use a predetermined array. ANy help or tips would be greatly appreciated.
6 Respostas
+ 2
You can use two pointers. 1 at the start and 1 at the end and if pointers end and start equal each other increment the pointers in farther till they reach the middle. else the word is not palindromic.
+ 1
You send the array and the length of it to the function and it will return true if the array is palindromic else false. You can also change the type of the array and it will work on any kind of array (in the function parameters)
+ 1
Your welcome :)
0
bool isPalindrom(int* arr, int length)
{
int i;
int j;
for(i=0, j=length-1; i!= j; i++, j--)
{
if(i + 1 == j && arr[i] == arr [j])
return true;
if(arr[i] != arr[j])
return false;
}
return true;
}
0
Thank you and how would I use that function for the array. Sorry I am new to C++ coding.
0
Okay thank you for your assistance :)