8) Write a Stack/Queue based method that determines whether or not an array of characters contains a palindrome. Does the Stack ADT indicate whether to use an array or linked list implementation? Why or why not?
Added by Mercedes R.
Close
Step 1
Here's a possible implementation in Python: ```python def is_palindrome(arr): stack = [] queue = [] # Push characters from the array onto the stack and queue for char in arr: stack.append(char) queue.append(char) # Pop Show more…
Show all steps
Your feedback will help us improve your experience
Willis James and 89 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
A palindrome is a string that reads the same forward and backward. Describe an algorithm for determining whether a string of $n$ characters is a palindrome.
Algorithms
Write a function named palindrome_word(). It takes in a string as the only parameter. It returns True if the string is a palindrome by words. Otherwise, it returns False. A sample run of one possible implementation is shown below.
Alexandra D.
Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following strings: madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindrome of Example 6-6 so that when determining whether a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. The isPalindrome function from Example 6-6 has been included below for your convenience. bool isPalindrome(string str) {int length = str.length(); for (int i = 0; i < length / 2; i++) { if (str[i] != str[length – 1 – i]) { return false; } // if } // for loop return true;}// isPalindrome Your program should print a message indicating if a string is a palindrome: madam is a palindrome
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD