Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java method called countAndDeleteKey in a class called StackEx that accepts an object st1 of type ArrayStack as the first parameter and key

Write a java method called countAndDeleteKey in a class called StackEx that accepts an object st1 of type ArrayStack as the first parameter and key of type E as the second parameter. The method will count the number of occurrences of key in st1 and will return this count. The method will also delete all occurrences of key from st1. All the remaining elements of st1 should be in the original relative order.

Example:

key = 5

Stack st1 before method call: 10 5 12 15 5 10 20 5 30 2 20

top

Stack st1 after method call: 10 12 15 10 20 30 2 20

top

As 5 (key) occurs 3 times in st1, the method will return 3.

Assume that class ArrayStack is available for use. Use common stack operations only such as push, pop, peek, isEmpty and copy constructor.

public class StackEx

{

public static int countAndDeleteKey(ArrayStack st1,E key)

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

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions