Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task1: Reverse a string using stack Given a string, reverse it using stack. For example, DataStructures should be converted to serutcurtSataD. 1) Create an empty

Task1: Reverse a string using stack Given a string, reverse it using stack. For example, DataStructures should be converted to serutcurtSataD. 1) Create an empty stack of characters 2) One by one push all characters of the given string to stack. 3) One by one pop all characters from the stack and assign them to another string. //Complete the below code public class ReverseWordStack { public int maxSize; public int top; public char[] myStack; public ReverseWordStack(int n) { //constructor top = -1; maxSize = n; myStack = new char[maxSize]; } Task2: Compute the factorial of a number using a stack Given a number n, calculate its factorial. For example, 6! = 720. 1) Create an empty stack of integers. 2) One by one push numbers n, n-1, n-2 .. 1 to stack. 3) One by one pop all numbers from the stack and multiply them each other. //Complete the below code public class FactorialNumberStack { public int maxSize; public int top; public int[] myStack; public FactorialNumberStack(int n) { //constructor top = -1; maxSize = n; myStack = new int[maxSize]; } Program code Screenshot including package explorer, program, console

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

How can Seaview improve their benefits communication? Discuss.

Answered: 1 week ago

Question

=+What is the most that you should pay to complete development?

Answered: 1 week ago