Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

his assignment is to utilize the author's stack code and queue code from chapter 4 to determine if a string is a alindrome (or not).

image text in transcribed

image text in transcribed

his assignment is to utilize the author's stack code and queue code from chapter 4 to determine if a string is a alindrome (or not). Note that an analysis of your two solutions is required to be compared to the algarithm give: a this documenf, A palindrome is a word that is spelled the same forwards and backwards. Assume that the phrase has been stripped of punctuation and is all the same case. For example, "A man, a plan i canal. Panamat" is entered as "amanaplancanalpanama" - Use the scanner class to input the data as a String - Modify the author's coce to stack a character instead of a long int o. The ONLY changes permitted are to the type of element on the stack - The modified code (StackX class in the file stack.java).must be in a separated class and a separate file - Similarly, modify the Queve code to use a character instead of a long int *. The ONLY changes permitted are to the type of element in the queve - The modified code (Queue class in the file queue.java) must be in a separated class and a separate file - Your main program should RESEMBLE this: public class PalindromeApp \{ public static yoid main(String[] args) \{ Scanner kbd = new Scanner (System. in); System.out, print("Enter a phrase (or 'quit'): "); String phrase =kbd. nextLine () ; while (!phrase.equals("quit")) t System.out. print(phrase); if (isPalindromeSTACK (phrase) \&\& isPalindromeQUEUE (phrase)) System.out. println(" is a palindnome"); System.out.println(" is NOT a palindrome"); System.out.print("Enter a phrase (or 'quit') : "); phrase =kbd. nextLine (); 3 I/ the input parameter "word" consists of zero or more characters /I this function determines if the initial word is a palindrome (true) /l or not (false) private static boolean isPalindromesTACK (String word) i 1/ your code that uses a stack will go in here ) private static boolean isPalindromeQUEUE(String word) i I/ your code that uses a queue will go in here Data Structure Requirements ( 40%) 1. No arrays are used in main, isPalindromeSTACK, and isPalindromeQUEUE. 2. String data types are permitted 3. Modified and used author's stack code Pop, Push, and isEmpty used 4. Modified and used author's queue code Algorithm Requirements (40\%) 1. Works! correctly identifies palindromes - Analysis Requirements (20\%) Use documentation for the lines in isPalindromeSTACK and isPalindromeQUEUE to show the running time of the code Analyze the following algorithm and compare the running time of the three solutions (i.e, code below, your isPalindromeSTACK and your isPalindromeQUEUE) for i from 0 to n/2 do if a[i] if a[ni] if in=n/2 return false else return true

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions