Trace the palindrome-recognition algorithm described in this section for eachof the following strings of characters:
a. abcda
b. radar
What will be an ideal response?
a.When the for loop ends, the stack and queue are as follows:
Stack: a d c b a ?bottom
Queue: a b c d a ?back
The a at the top of the stack matches the a at the front of the queue. After removing the a from both containers, the d at the top of the stack does not match the b at the front of the queue, so the string is not a palindrome.
b.When the for loop ends, the stack and queue are as follows:
Stack: radar?bottom
Queue: radar?back
The letters that you remove from the stack and the queue are the same, so the string is a palindrome.
You might also like to view...
The tool that allows you to capture a color from one object and apply it to another is the ________
Fill in the blank(s) with correct word
The ____ compositor defines a specific order for the child elements.
A. choice B. all C. target D. sequence