logo CodeStepByStep logo

isPalindrome

Language/Type: C++ collections Stack Queue
Related Links:

Write a function named isPalindrome that takes a reference to a queue of integers as a parameter and returns true if the numbers in the queue represent a palindrome (and false otherwise). A sequence of numbers is considered a palindrome if it is the same in reverse order. For example, suppose a queue called q stores these values:

{3, 8, 17, 9, 17, 8, 3}

Then the call of isPalindrome(q); should return true because this sequence is the same in reverse order. If the queue had instead stored these values:

{3, 8, 17, 9, 4, 17, 8, 3}

The call on isPalindrome would instead return false because this sequence is not the same in reverse order (the 9 and 4 in the middle don't match). The empty queue should be considered a palindrome. You may not make any assumptions about how many elements are in the queue and your function must restore the queue so that it stores the same sequence of values after the call as it did before. You may use one stack as auxiliary storage.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.