Palindrome with Stack Program
Description
The program inputs a string and uses a stack to determine whether or not it is a palindrome.Associated Concepts:
Stack
Algorithm:
main method:
evaluate method definition:
Input a string and convert it to all uppercase letters, and then
remove blank spaces and punctuations.
Call evaluate() method to get the returned boolean status.
Print a message to indicate whether or not the input string is a palindrome based on the returned status.
Call evaluate() method to get the returned boolean status.
Print a message to indicate whether or not the input string is a palindrome based on the returned status.
evaluate method definition:
In the first loop, retrieve each character of the input string in order
(from the first character to the last character) and push
it onto the first stack.
In the second loop, retrieve each character of the input string in the reverse order (from the last character to the first character) and push it onto the second stack.
In the third loop, pop a pair of objects from stack1 and stack2, compare them.
In the second loop, retrieve each character of the input string in the reverse order (from the last character to the first character) and push it onto the second stack.
In the third loop, pop a pair of objects from stack1 and stack2, compare them.
If they are equal, the process continues.
Otherwise, return false.
After the third loop ended, return true.
Otherwise, return false.