Question: On a java application need to create a new class that is similar to the Stack class but your new class is to keep the
On a java application need to create a new class that is similar to the Stack
For example, if you push the following integers onto the stack in this order 55,1,32,7,44,2 When pop() is called the very first time, the number 1 will be returned. The 2nd call to pop() will return the number 2. The 3rd call to pop() will return 7. The 4th call to pop() will return 32, and so on.
You must create a PriortyStack class with at least three methods.
- A method to push a value onto the stack
- A method to pop a value off the stack
- A method to determine if the stack is empty
Print the contents of the stack by repeatedly calling the pop() method to demonstrate the stack has its items in priority order.
HINTS
- Use the Stack
class as a starting point . - The items in your list must be comparable, meaning your class will be PriorityStack
> not just PriorityStack - Remember, Collections.sort() will sort the contents of a list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
