Oops late reply…
That is my solution.
I wrote 2 extra supporting functions along the top.
bool isEven(std::vector myVector)
bool isVectorEqual(std::vector firstVector, std::vector secondVector)
Anyways the pseudo-code for my design is this.
First I convert the String into a vecor char Array. (Line 37 to 43)
I first check if the char entered in the function is EVEN (abab) or ODD (abcba).
Example: Even char vector “abab” array…
Odd char vector “abcba” array…
If it is EVEN, I take the first 2 char and compare it to last 2 char using a for loop.
One scans from ab, and the other scans from ba. (Line 54 to 83)
ab != ba, thus the function is_palindrome(“abab”); should return FALSE.
If it is ODD, I ignore the middle char, compare the first 2 char ab and the last 2 char ba using a for loop. One scans from ab, and the other scans from ab. (Line 84 to 112)
ab == ab (Equal), thus the function is_palindrome(“abcba”); should return TRUE.
If you do it yourself, in your decrement loop, make sure it’s something like this.
for (int k=charVector.size()-1; k> (charVector.size()-1)/2; k–)
If you forgot to decrease 1 from the initial k, the decrement loop will go OUT OF BOUNDS!!
This code is a source of headache. “k> (charVector.size()-1)”
I literally traced the code using paper. https://photos.app.goo.gl/gwkNchG696hSL2qa8
Lets say you have a VECTOR with size 7. It is stored in computer labeled 0,1,2,3,4,5,6…
You have to go through position 0, 1, 2… ignore 3… position 4, 5, 6.
Remember, the SIZE function will return 7.
If you count from 0, it is easy.
for (int i=0; i< (charVector.size() - 1) /2; i++) //middle function will return 3
//Scan position 0, 1, 2, which is correct.
But if you count from end to middle, you have to do this.
for (int k=charVector.size()-1; k> (charVector.size()-1)/2; k–) //initial=6, middle=3, decrement
//Scan from position 6, 5, 4… the code ignores position 3 because the conditional is “greater than”.
Imagine trying to find the bug when your initial condition at a loop is out of bounds!!
I wanted to rip my hair out at this project, but I did it!! YAAAAAAAAAAY!!