Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

all in java coding CS 205 Lab 4 - Stack Objectives: Learn How to Implement Stack using Doubly Linked List Learn How to Use Stack

image text in transcribed

all in java coding

image text in transcribed

CS 205 Lab 4 - Stack Objectives: Learn How to Implement Stack using Doubly Linked List Learn How to Use Stack . . Examples: 1. Class TestintegerLL Stack shows how to use the LL Stack implemented in the Lecture. It performs the following operations: Push an element Pop an element and print it Get top element and print it Print all elements in the stack Clear the stack Quit 2. Class Reverse String shows how you may use stack to reverse a string 3. Class AddLargeIntegers shows how use stack to add large integers as discussed in the lecture 4. Class TestDelimiterMatching showa how stack can be used to check is an expression has matching brackets, (),[] or { }. Tasks: 1. The given file DLL.java implements generic linked list as we saw in Lab03. It has been updated to include additional methods needed for Stack/Queue implementation: getLast(), and toString(). (a). Use this class to implement a class, DLL Stack, that represents a stack for processing any types of values. (b) Save TestintegerLLStack as TestDoubleStack, and update it to use your DLL Stack in (a) above to manage double values. (c) Save TestDouble Stack as TestStudentStack, and update it to manage Student objects. 2 A simple algorithm to check if a string is a palindrome (reads the same either from left or from right: e.g: Madam) is as follows: Scan through the string and store each character in a stack Scan through the string the second time comparing each character with the next character pop off from the stack. there is a mismatch at any point, the string is NOT a palindrome. If no mismatch is found at the end of the scan, then the string is a palindrome. Use the DLLStack to write a program, TestPalindrome, that has the following methods: (a)public static boolean is Palindrome(String s): That uses the above algorithm to check and returns true if s is palindrome or false otherwise. (b)main() method: That reads a string from a user, calls the isPalindrome() to check and displays a message indicating whether the string is a palindrome or not. 3. Assuming that a postfix expression consists of operands of single digits (0,1, .., 9), the binary operators *, /,%, +, and, and possibly white-space characters. An algorithm to evaluate the postfix expression as discussed in the class is given below: Create an empty stack of Integer type. Read postfix expression as a string while(there are more characters in the string> if(current character is an operand) covert character to int and push in the stack; else if(current character is an operator oprt) operand 1 = pop stack; operand2 = pop stack; result = operand2 oprt operand1; push result in the stack; } } pop result from the stack and print it; Use DLL Stack to write a Java program, TestPostfix, that has the following methods: (c)public static int evaluate(String postfix): That takes a postfix string as argument, evaluate it using the above algorithm and returns the result. (d)main() method: That prompts for and reads a postfix expression from then user, then calls the evaluate() method to evaluate it and displays the result. Sample input/output: postfix expression 5 9 + 2 * 6 5 6 2 + 5 8 4/ . * 6 2 + 5 * 8 4 / + value 58 24 38

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Define TRA, or total rewards package.

Answered: 1 week ago

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago