views:

20

answers:

1

Hi all,

I need a priority queue of objects but I keep getting this error:

symbol: constructor PriorityQueue(anonymous java.util.Comparator<map.Node>>)
location: class java.util.PriorityQueue<map.Node>
  PriorityQueue<Node> pq = new PriorityQueue<Node>(new Comparator<Node>() 

Here an excerpt from my code:

public class map {

 static class Node {
  Node parent;
  State state;
  private int cost;
  public Node() {};
  public Node(Node parent_passed, State state_passed, Integer cost_passed ) { 
  this.parent = parent_passed; 
  this.state = state_passed;
  this.cost = cost_passed;
  }
  public int getCost()
  {
   return cost;
  }

  }

 public static void main(String[] args) 
 {
  PriorityQueue<Node> pq = new PriorityQueue<Node>(new Comparator<Node>() 
  {
   public int compare(Node a1, Node a2) {
    return a2.getCost() - a1.getCost(); 
   }
  });


 }

Any ideas? Do I need to make the Node class public and put it in it's own file?

+1  A: 

You trying to use a constructor that doesn't exist to create the PriorityQueue object. There is no PriorityQueue(Comparator) constructor defined in the JavaDoc (http://download.oracle.com/javase/6/docs/api/java/util/PriorityQueue.html). It does have one that takes an int for initialCapacity and a comparator, you might want to try that.

Dante617