Java : Write the Java code segment that uses a stack to determine if a string is a palindrome (assume all that blanks have been removed). A palindrome contains the same characters forwards as backwards, for example level is a palindrome. Your solution must use only a stack, you MUST process the string from left to right, and are allowed to go through the string only once.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

Java :

Write the Java code segment that uses a stack to determine if a string is a palindrome (assume all that blanks have been removed). A palindrome contains the same characters forwards as backwards, for example level is a palindrome. Your solution must use only a stack, you MUST process the string from left to right, and are allowed to go through the string only once.  You must use an efficient algorithm. 

Use :

ArrayStack class given below:

/**

    * Creates an empty stack using the default capacity.

    */

    public ArrayStack()

    {

        this(DEFAULT_CAPACITY);

    }

    /**

     * Creates an empty stack using the specified capacity.

     * @param initialCapacity the initial size of the array

     */

    public ArrayStack(int initialCapacity)

    {

        top = 0;

        stack = (T[])(new Object[initialCapacity]);

    }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Stack
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,