📄 vertex.java
字号:
public class Vertex implements Comparable {
String vertexString;
public Vertex() {
} // default constructor
public Vertex (String s) {
vertexString = s;
} // default constructor
public String toString() {
return vertexString;
} // method toString
public boolean equals (Object v) {
return vertexString.equals (((Vertex)v).vertexString);
} // method equals
public int compareTo (Object v) {
return vertexString.compareTo (((Vertex)v).vertexString);
} // method compareTo
public int hashCode() {
return vertexString.hashCode();
} // method hashCode
} // class Vertex
class EdgeTriple implements Comparable {
Vertex from,
to;
double weight;
// Postcondition: this EdgeTriple has been initialized from v1, v2 and weight.
public EdgeTriple (Vertex v1, Vertex v2, double weight) {
from = v1;
to = v2;
this.weight = weight;
} // default constructor
// Postcondition: the from vertex in this EdgeTriple has been returned.
public Vertex getFromVertex() {
return from;
} // method getFromVertex
// Postcondition: the "to" vertex in this EdgeTriple has been returned.
public Vertex getToVertex() {
return to;
} // method getToVertex
// Postcondition: the weight in this EdgeTriple has been returned.
public double getWeight() {
return weight;
} // method getWeight
// Postcondition: an int <, = or > 0 has been returned, depending on
// whether this EdgeTriple's weight is <, = or > edge's weight.
public int compareTo (Object edge) {
Double thisWeight = new Double(weight);
Double otherWeight = new Double(((EdgeTriple)edge).getWeight());
return thisWeight.compareTo(otherWeight);
} // method compareTo
// Postcondition: the String corresponding to this EdgeTriple
// has been returned.
public String toString() {
return from.toString() + " " + to.toString() + String.valueOf (weight);
} // method toString
} // class EdgeTriple
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -