1: 前面已经介绍了无向图是不带权值的 ,现在看带权值的无向图
权值 的定义类 两个点 一个权重
/**
* 边
* @author lijunqing
*/
public class Edge implements Comparable<Edge> {
private final int v;
private final int w;
private final double weight;
public Edge(int v, int w, double weight) {
this.v=v;
this.w=w;
this.weight=weight;
}
/**
* 取的另一点
* @param other
* @return
* @throws NoSuchAlgorithmException
*/
public int other(int other) throws NoSuchAlgorithmException {
if(v == other)
return w;
else if(w == other)
return v;
else
throw new IllegalArgumentException("illegal");
}
/**
* 根据weight比较大小
*/
@Override
public int compareTo(Edge other) {
if(this.weight - other.weight > 1) {
return 1;
} else if(this.weight - other.weight == 0) {
return 0;
}
return -1;
}
}