I'm writing a program to see if a string is a palindrome. I'm having trouble with the implementing the queue.enqueue(nextCharacter), stack.push(nextCharacter), queueFront = queue.peekFront(), stackTop = stack.peek(), queue.dequeu(). I tried looking at examples online of implementations of peek(), deque, push, and enqueue. Could not find any that worked correctly
I have to follow the exact format I had from the code above that I posted.
Here is the algorithm I'm trying to follow:
isPalindrome(someString: string): boolean
{
// Create an empty queue and stack
aQueue = new empty queue
aStack = new empty stack
// Add each character of string to both queue and stack
length = length of someString
for (i= 1 throught length)
{
nextChar = ith character of someString
aQueue.enqueue(nextChar)
aStack.push(nextChar)
}
charactersAreEqual=true
// Compare queue characters with stack characters
while (aQueue is not empty and charactersAreEqual)
{
queueFront = aQueue.peekFront();
stackTop = aStack.peek()
That code is not syntactically correct for C++ using the standard containers. eg. std::queue doesn't have a method '.peekFront()' It's .front(). My code above follows the specified/required logic.