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 class but your new class is to keep the items pushed onto the stack in priority order. The item with the lowest value would be popped from the stack first.

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.

  1. A method to push a value onto the stack
  2. A method to pop a value off the stack
  3. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!