vertexweightpair.java
来自「Network数据结构与算法分析中 图的实现 相当全面 请需要的朋友们下载」· Java 代码 · 共 56 行
JAVA
56 行
public class VertexWeightPair implements Comparable {
Vertex to; // the "from" vertex is implicit
double weight;
// Postcondition: this VertexWeightPair has been initialized from vertex and weight.
public VertexWeightPair (Vertex vertex, double weight) {
to = vertex;
this.weight = weight;
} // default constructor
// Postcondition: the "to" vertex in this VertexWeightPair has been returned.
public Vertex getToVertex() {
return to;
} // method getToVertex
// Postcondition: the weight in this VertexWeightPair has been returned.
public double getWeight() {
return weight;
} // method getWeight
// Postcondition: an int <, = or > 0 has been returned, depending on
// whether this VertexWeightPair's weight is <, = or >
// VertexWeightPair's weight.
public int compareTo (Object vertexWeightPair) {
Double thisWeight = new Double(weight);
Double otherWeight = new Double(((VertexWeightPair)vertexWeightPair).getWeight());
return thisWeight.compareTo(otherWeight);
} // method compareTo
// Postcondition: a String representation of this VertexWeightPair
// has been returned.
public String toString() {
return to.toString() + " " + String.valueOf (weight);
} // method toString
} // class VertexWeightPair
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?