Question
Code in JAVA public interface Stack { /** * Returns the number of elements in the stack. * @return number of elements in the stack
Code in JAVA
public interface Stack
/** * Tests whether the stack is empty. * @return true if the stack is empty, false otherwise */ boolean isEmpty();
/** * Inserts an element at the top of the stack. * @param e the element to be inserted */ void push(E e);
/** * Returns, but does not remove, the element at the top of the stack. * @return top element in the stack (or null if empty) */ E top();
/** * Removes and returns the top element from the stack. * @return element removed (or null if empty) */ E pop(); }
A palindrome is a word, phrase, or sentence that reads the same backwards as forwards (with punctuations ignored). For example, A man, a plan, a canal: Panama. is a palindrome. King, are you glad you are king? is not a palindrome Implement the generic Arraystack that we discussed in class and include a toString method. The Stack interface of our ADT is provided. Create a driver class that declares a Stack as an instance of Arraystack and use it to see if a word or phrase entered by the user is a palindrome. Refer to the algorithm for reversal that we discussed in class but do not use this generic method. Declare and use the stack in main. Display the result of the palindrome test. For example, Enter a word, phrase, or sentence: A man, a plan, a canal: Panama. is a palindromeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started