Page 3 of 3 FirstFirst 123
Results 41 to 49 of 49
  1. #41
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by niu_niu View Post
    To get the right order, you have to actually remove items from a priority queue. The priority queue actually does a few more compareTo's when removing items.

    Berkeleybross
    Where can I find the CompareTo code? it is not obvious to me how it is doing a few compareTo's.
    A priority queue is a heap; when it removes its top element (the ony with the highest priority) it has to reconstruct its heap so it needs to compare a few elements to do it.

    kind regards,

    Jos

  2. #42
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    The priority queue itself is doing the compareTo's. You dont need to know when or why or how it is doing it.

    All you need to do is make sure that your person1 compareTo method is returning a "negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object".


    All I was saying in my last post was that printing out the contents of the array is not *guarenteed* to be in the correct order. However when you remove an element from the array it is guarenteed to be the right one.

  3. #43
    niu_niu is offline Member
    Join Date
    Jun 2010
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by berkeleybross View Post
    The priority queue itself is doing the compareTo's. You dont need to know when or why or how it is doing it.
    you are talking like a priest. i am an engineer.

  4. #44
    niu_niu is offline Member
    Join Date
    Jun 2010
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    A priority queue is a heap; when it removes its top element (the ony with the highest priority) it has to reconstruct its heap so it needs to compare a few elements to do it.

    kind regards,

    Jos
    where can I find the code that shows this?

  5. #45
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Here is an example of a priority queue implementation. I don't know if thats the exact java.util.priority queue.

    Dont ask me to explain it though!

  6. #46
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by niu_niu View Post
    where can I find the code that shows this?
    Look in the directory where your jdk (javac etc.) is stored; there's a src.zip file there that contains the source files for the entire public API classes. The source code for the PriorityQueue is also in there somewhere.

    kind regards,

    Jos

  7. #47
    niu_niu is offline Member
    Join Date
    Jun 2010
    Posts
    48
    Rep Power
    0

    Default

    Cool...that's what I was looking for. Since my kisses got rejected last time, I guess I will just say thank you for now.

  8. #48
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by niu_niu View Post
    Cool...that's what I was looking for. Since my kisses got rejected last time, I guess I will just say thank you for now.
    I didn't reject anything; granted, I didn't accept them either because I never read about such mundane physical contact in these forums.

    kind regards,

    Jos

  9. #49
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Forget about the actual numbers returned.
    That's irrelevant.

    Are you questioning the order?
    In which case can we have an example?
    Because the stuff you posted above is correct for ordering Strings.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. priority
    By simorgh in forum Threads and Synchronization
    Replies: 4
    Last Post: 01-07-2012, 12:49 AM
  2. Priority Queue Question
    By Taz_84 in forum New To Java
    Replies: 0
    Last Post: 01-29-2009, 03:23 AM
  3. How to implement Priority queue with Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:49 PM
  4. How to get/set thread priority
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:40 PM
  5. Java experts needed- 30 minute online Java projects
    By michelle in forum Jobs Offered
    Replies: 0
    Last Post: 03-05-2008, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •