Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named StackOfStrings that contains a. A private array elements to store String in the stack b. A private data field size to

image text in transcribed
Design a class named StackOfStrings that contains a. A private array elements to store String in the stack b. A private data field size to store the number of String in the stack c. A constructor to construct an empty stack with a default capacity of 4. d. A constructor to construct an empty stack with a specified capacity. e. A method empty that returns true if the stack is empty f. A method push(string value) that stores value at the top of the stack. This method checks if the stack is full before pushing to it. In case the stack is full, it I. copies the contents of the stack to a new temp array ii. creates a new elements array with double the current capacity iii. copies back temp to elements iv. places value at the top of the new stack g. A method pop that removes the string at the top of the stack and returns it. In case the stack is empty, it returns "Stack is EMPTY" h. A method peeko that returns the string at the top of the stack without removing it from the stack. In case the stack is empty, it returns Stack is "EMPTY i. A method printStack() as shown below: public void printStack! System.out.print("Stack (top to bottom): "); for (int i=size-1; i>-1; i--) System.out.print(elements[i] + System.out.println(;)

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 Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago