Question: For this exercise you are defining a function which uses the Stack ADT and the Queue ADT. The implementations of both the Stack and Queue
For this exercise you are defining a function which uses the Stack ADT and the Queue ADT. The implementations of both the Stack and Queue ADTs are provided for you as part of this exercise and you can use the methods:
Stack(), push(), pop(), is_empty()
as well as
Queue(), enqueue(), dequeue(), is_empty()
as necessary in your function code.
A palindrome is a sequence of letters which read the same as the sequence in reverse: for example, "noon" is a palindrome whereas "noone" is not. Single characters are also palindrome.
Write the is_palindrome(letters) function which takes a string, letters, as a parameter and determines whether the string is a palindrome or not. You can assume the input is a valid string and all characters are in lower case. You must make use of a stack and a queue to test the parameter string.
Note: you should not use list indexes (i.e. square brackets) or call Python list methods such as reverse(). Your solution should use a loop (to iterate over the characters in the parameter letters), and a Stack and a Queue object.
For example:
| Test | Result |
|---|---|
print(is_palindrome("abcdef")) | False |
print(is_palindrome("nonon")) | True |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
