Author | Message |
---|---|
pgatsby
Posts: 10
|
Posted 17:27 Oct 24, 2018 |
So I am almost finished with the assignment except one thing has be stumped. I implemented comparable into Victims and also comparator. The priority queue for victims automatically becomes sorted by the comparable implementation, how ever I do not know how to resort the list using comparator? |
dtang9
Posts: 52
|
Posted 17:52 Oct 24, 2018 |
I think you should create a separate class that implements comparator. I got this quote about Comparator from Lecture 9 Slide 6: "It is typically implemented in a class which exists only for this purpose." |
jhurley
Posts: 207
|
Posted 08:22 Oct 25, 2018 |
yes, create a separate class for the Comparator. When you create the PQ, you use a slightly different constructor call to indicate that it should use your Comparator- see the products example. Doing it this way makes it possible to create multiple Comparators so you can sort in as many ways as you need to at different times. |