2016-05-02 8 views
-1

私は、Comparableを実装し、equalsをオーバーライドするVertexクラスを持っています。equalsとcompareToをオーバーライドした後にPriorityQueueを使用します。

public class Vertex implements Comparable<Vertex>{ 

private final int x; 
private final int y; 
private final char c; 

public Vertex(int x, int y, char c) { 
    this.x = x; 
    this.y = y; 
    this.c=c; 

} 

public double heuristic(Vertex goal){ 
    double dx = Math.abs(x - goal.x); 
    double dy = Math.abs(y - goal.y); 
    return Math.sqrt(Math.pow(dx, 2)+Math.pow(dy, 2)); 
} 


@Override 
public String toString() { 
    return ("(" + x + "," + y + ")"+"["+c+"]"); 
} 

@Override 
public int compareTo(Vertex v) { 
    // TODO Auto-generated method stub 
    if(this.heuristic(end)<v.heuristic(end)) return -1; 
    return 1; 
} 
public boolean equals(Vertex v){ 
    if(this.x==v.x && this.y==v.y) return true; 
    return false; 
} 

/* 
public boolean equals(Object o){ 
    if(o.getClass().getName()=="Vretex"){ 
     Vertex v=(Vertex)o; 
     return this.equals(v); 
    } 
    return false; 
} 
*/ 

} 

Iの優先度つきキューを使用して、一つのオブジェクト(異なるオブジェクト)場合は同等の機能を記載等しい機能は、私は偽得る優先度つきキューにあることを確認してください。

また、コメントなしで成功しなかった。

答えて

関連する問題