0

Is the java API PriorityQueue constructor that takes another priority queue destructive to the argument? If so, is its clone() method adequate for creating a shallow copy?

1 Answer 1

2

No, it is not destructive. Pretty much all the collection classes have copy constructors, and are non-destructive by convention.

The reason there are overloaded constructors is for efficiency; when a PQ or SortedSet is supplied, one can imagine that the initial population of elements can be O(n) instead of O(n log n)

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.