1

I need to "Create an instance of the Stack class with a max size of 50" and
"Create four instances of the PriorityQueue class, each with a max size of 10."

I know how to create an instance of a class, but how do I create them with a max size? It's probably something really simple, but I've searched for about 10 mins without finding relevant info.

1

1 Answer 1

1

If you want to put a hard limit on either of those classes, you'll have to extend them.

It's fairly simple to do this for both classes. All you have to do is override the method that handles adding elements, and add a check to make sure the addition won't make the size of the class go over the max size.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.