Question: 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
