加权有向图介绍(内含代码详解)

加权有向图

API设计
在这里插入图片描述
代码实现:

public class DirectedEdge {
    private final int v;//起点
    private final int w;//终点
    private final  double weight;//当前边的权重

    public DirectedEdge(int v,int w,double weight){
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    /**
     * 获取边的权重值
     * @return
     */
    public double weight(){
        return weight;
    }

    /**
     * 获取有向边的起点
     * @return
     */
    public int from(){
        return v;
    }

    /**
     * 获取有向边的终点
     * @return
     */
    public int to(){
        return w;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43751200/article/details/105628322