/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.datastructure.graph;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 有向图且带权重
 * @author cwenao
 * @version $Id DirectedAndEdgeWeightGraph.java, v 0.1 2017-08-25 08:50 cwenao Exp $$
 */
public class DirectedAndEdgeWeightGraph<T extends Comparable> {

    private static final Logger LOG = LoggerFactory.getLogger(DirectedAndEdgeWeightGraph.class);

    private int V; //the number of vertexes
    private int E; //the edge of with the vertexes
    private Bag<DirectedEdge>[] adj; //the adj for grap
    private int[] indegree; //this is the number for the edge

    public DirectedAndEdgeWeightGraph(int V) {
        this.V = V;
        this.E = 0;
        this.adj = new Bag[V];
        this.indegree = new int[V];
        for (int v=0;v<V;v++) {
            adj[v] = new Bag<>();
        }
    }


    public DirectedAndEdgeWeightGraph(int V, int E) {
        this(V);

    }

    public void addEdge(DirectedEdge edge) {
        int from = edge.getVertexFrom();
        int to = edge.getVertexTo();

        adj[from].add(edge);
        indegree[to]++;
        E++;
    }



}

@@ -159,16 +159,42 @@
 ctory;%0A%0A
+import java.util.Random;%0A%0A
 /**%0A * %E6%9C%89
@@ -998,213 +998,846 @@
 V);%0A
-%0A    %7D%0A%0A    public void addEdge(DirectedEdge edge) %7B%0A        int from = edge.getVertexFrom();%0A        int to = edge.getVertexTo();%0A%0A        adj%5Bfrom%5D.add(edge);%0A        indegree%5Bto%5D++;%0A        E++;%0A    %7D%0A%0A%0A
+        Random random = new Random(3);%0A        for(int i=0;i%3CE;i++) %7B%0A%0A            int from = random.nextInt(V);%0A            int to = random.nextInt(V);%0A            double weight = Math.random() * 10;%0A            DirectedEdge directedEdge = new DirectedEdge(from, to, weight);%0A            addEdge(directedEdge);%0A        %7D%0A%0A    %7D%0A%0A    public void addEdge(DirectedEdge edge) %7B%0A        int from = edge.getVertexFrom();%0A        int to = edge.getVertexTo();%0A%0A        adj%5Bfrom%5D.add(edge);%0A        indegree%5Bto%5D++;%0A        E++;%0A    %7D%0A%0A    public Iterable%3CDirectedEdge%3E adj(int v) %7B%0A        return adj%5Bv%5D;%0A    %7D%0A%0A    public int outdegree(int v) %7B%0A        return adj%5Bv%5D.size();%0A    %7D%0A%0A    public int indegree(int v) %7B%0A        return indegree%5Bv%5D;%0A    %7D%0A%0A    public int getV() %7B%0A        return V;%0A    %7D%0A%0A    public int getE() %7B%0A        return E;%0A    %7D
 %0A%7D%0A

update the directed graph