Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Write a program that uses a stack to test input strings to determine whether they
are palindromes. A palindrome is a sequence of words that reads the same as the
sequence in reverse: for example, noon.

 

Use this Python Example :

class Stack:
'''
TODO: Remove the "pass" statements and implement each method
Add any methods if necesssary
DON'T use any builtin stack class to store your items
'''
def __init__(self): # Constructor function
pass
def isEmpty(self): # Returns True if the stack is empty or False otherwise
pass
def len(self): # Returns the number of items in the stack
pass
def peek(self): # Returns the item at the top of the stack
pass
def push(self, item): # Adds item to the top of the stack
pass
def pop(self): # Removes and returns the item at the top of the stack
pass
def palindrome(input_str):
isPalindrome = False
#TODO: Your work here
# Return if input_str is palindrome or not
return isPalindrome
if __name__ == "__main__":
my_str = "noon"
print(palindrome(my_str)) # Correct Output: True
#TODO (optional): Your testing code here

Expert Solution
Check Mark
Algorithm
  1. Create a Stack class to represent a stack data structure.
  2. Define a palindrome function that takes an input string input_str.
  3. Create an empty stack.
  4. Push each character in input_str onto the stack.
  5. Pop each character off the stack and compare it to the corresponding character in input_str.
  6. If any characters don't match, isPalindrome is set to False.
  7. Return isPalindrome.
  8. In the main function, test the palindrome function with an input string and print the result.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education