title: Java Priority Queue Not Sorting Properly
body: <p>I am trying to implement a priority queue of my class type BBNode, but it doesn't seem to sift up the new nodes the way I expect it. Rather than have the smallest be at the head of the queue (how it works now), I want the largest to be there, but I can't figure out how to make this work. Here's my BBNode class.</p>
  
  <pre><code>public class BBNode implements Comparable&lt;BBNode&gt;{
      public int level; //level on the tree
      public int value; //value up to that node
      public int weight; //weight up to that node
      public double bound; //bound of that node
  
      //...constructors
      public int compareTo(BBNode node){
          if(this.bound &gt; node.bound) return -1;
          if(this.bound &lt; node.bound) return 1;
          return 0;
      }
  }
  </code></pre>
  
  <p>And here's where I use the PQ.</p>
  
  <pre><code>PriorityQueue&lt;BBNode&gt; pq = new PriorityQueue&lt;BBNode&gt;();
  //..other variables
  while(pq.peek() != null){
    v = pq.poll();
    //System.out.println(v.weight + " " + v.value + " " + v.bound);
    if(v.bound &gt;= bestVal &amp;&amp; v.level &lt; sortedItems.length-1){
       //left branch: take the next item
       u.level = v.level+1;
       u.weight = v.weight + sortedItems[u.level].weight;
       u.value = v.value + sortedItems[u.level].value;
       u.bound = bound(u);
       //System.out.println(u.bound);
       if(u.bound &gt; bestVal){
          pq.add(u);
          System.out.println("adding " + u.bound);
          System.out.println("top of pq is " + pq.peek().bound);
       }
       if(u.weight &lt;= maxWt &amp;&amp; u.value &gt; bestVal){
          bestVal = u.value;
          bestWt = u.weight;
          //System.out.println(bestVal + " " + bestWt);
          takeList[arrIdx++] = sortedItems[u.level].item+1;
       }
       //right branch: don't take the next item
       u.weight = v.weight;
       u.value = v.value;
       u.bound = bound(u);
       if(u.bound &gt; bestVal){
          pq.add(u);
          System.out.println("adding " + u.bound);
          System.out.println("top of pq is " + pq.peek().bound);
       }
    }
  }
  </code></pre>
  
  <p>Sorry the formatting at the end sucks. The last bracket corresponds to the while loop.</p>
  
  <p>I've also tried switching around the -1 and 1 in the compare method, and I've also tried implementing a Comparator, but with the same results.</p>
  
  <p>Any help is appreciated :)</p>