{ nextChar = i th character of someString aQueue.enqueue(nextChar) aStack.push(nextChar) } // Compare the queue characters with
Fantastic news! We've Found the answer you've been seeking!
Question:
{
nextChar = i
th character of someString
aQueue.enqueue(nextChar)
aStack.push(nextChar)
}
// Compare the queue characters with the stack characters
charactersAreEqual = true
while (aQueue is not empty and charactersAreEqual)
{
queueFront = aQueue.peekFront()
stackTop = aStack.peek()
if (queueFront equals stackTop)
{
aQueue.dequeue()
aStack.pop()
}
else
charactersAreEqual = false
}
return charactersAreEqual
Question 3
Trace the palindrome-recognition algorithm described in this section for each of the following strings of characters:
a. abcda
b. radar
Question 4
Improve the palindrome-recognition algorithm described in this section by adding the first length / 2 characters to the queue and then pushing the remaining characters onto the stack.
Related Book For
Posted Date: