Which implementation is less “heavy”: PriorityQueue or a sorted LinkedList (using a Comparator)?
I want to have all the items sorted. The insertion will be very frequent and ocasionally I will have to run all the list to make some operations.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
LinkedListis the worst choice. Either use anArrayList(or, more generally, aRandomAccessimplementor), orPriorityQueue. If you do use a list, sort it only before iterating over its contents, not after every insert.One thing to note is that the
PriorityQueueiterator does not provide the elements in order; you’ll actually have to remove the elements (empty the queue) to iterate over its elements in order.