
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

- Create a Stack class to represent a stack data structure.
- Define a palindrome function that takes an input string input_str.
- Create an empty stack.
- Push each character in input_str onto the stack.
- Pop each character off the stack and compare it to the corresponding character in input_str.
- If any characters don't match, isPalindrome is set to False.
- Return isPalindrome.
- In the main function, test the palindrome function with an input string and print the result.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

- Please write in JAVA, Im trying to get a program that Returns first index where given value is found in list (if exist). param value - value to be searched. return first index of the value or -1 if value does not exist public boolean set(int index, int value) throws IndexOutOfBoundsException { //Implement this method return false; }arrow_forwardI want to make a JAVA program that will allow me to insert 2 #'s and will start from 1 # and count downward or upward to the 2nd #. This is the code I have so far, but nothings coming out right. Please let me know if that is possible and if so, please fix my codearrow_forwardJAVA PROGRAM MODIFY THIS PROGRAM SO IT READS THE TEXT FILES IN HYPERGRADE. I HAVE PROVIDED THE INPUTS AND THE FAILED TEST CASE AS A SCREENSHOT. HERE IS THE WORKING CODE TO MODIFY: import java.io.*;import java.util.*;public class NameSearcher { private static List<String> loadFileToList(String filename) throws FileNotFoundException { List<String> namesList = new ArrayList<>(); File file = new File(filename); if (!file.exists()) { throw new FileNotFoundException(filename); } try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String[] names = line.split("\\s+"); for (String name : names) { namesList.add(name.toLowerCase()); } } } return namesList; } private static Integer searchNameInList(String name, List<String> namesList) {…arrow_forward
- I need help coding this in Java language pleasearrow_forwardJAVA: Write a recursive method named threeSum that accepts a list of integers and prints all combinations of three integers in the list that sum to 0. For example, if given the list [-1, 0, 1, 2, -1, -4], print the following lines of output: [-1, 0, 1] [-1, 2, -1] [0, 1, -1] You may print the lines of output in any order. The elements in each three-element sublist should appear in the same relative order that they appeared in the original list. Do not print duplicate lists; if the same exact sublist can be made in multiple ways, print it only once. If there are no combinations of three elements that sum to 0, print no output. The list passed to your method must be back to its original state at the end of the call. Either do not modify it, or if you modify it, fully undo your modifications before the method returns. Constraints: Do not declare any global variables. You can use any data structures you like, and your code can contain loops, but the overall algorithm must be recursive and…arrow_forwardin java please Create a method for the client perspective to determine if a ListInterface has the same numbers in the same order. method header: public static boolean equivalentLists(ListInterface<Integer> numberListInterface, List<Integer> numberList)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





