计算有向图的indegree和outdegree

时间:2017-05-13 10:16:29

标签: java digraphs

首先,我在移动设备上,所以这可能看起来不太漂亮,因为典型的编辑选项不可用。我对如何找到凹凸不平的东西感到有些困惑。这是Coursera提供的。我知道,在度数中,边缘进出的程度是边缘出去

 import java.util.*;
 import java.io.*;

 class UnweightedGraph<V>
    {
//A HashMap of lists for Adjacency list representation. Key is a   source vertex and 
//value is a list of outgoing edges (i.e., destination vertices) for the key
private HashMap<V,LinkedList<V>> adj;

public UnweightedGraph()
{
    adj = new HashMap<V,LinkedList<V>>();
}

/**
 * A function to add an edge
 * @param source : The source of the edge
 * @param dest: The destination of the edge
 */

public void addEdge(V source, V dest)
{
    LinkedList<V> edgeList = adj.get(source);
    if (edgeList==null)
        edgeList = new LinkedList<V>();

    edgeList.add(dest);
    adj.put(source, edgeList);
}







 /**
 * Computes the in-degree and outDegree for each vertex in the graph
 * @returns a dictionary which maps every vertex to its Degree object containing the in-degree and out-degreeo of the vertex
 */
  public Map<V, Degree> findInOutDegrees()
   {
// TO DO : YOUR IMPLEMENTATION GOES HERE
//Map <V, Degree > computeInOutDegree = new HashMap<V,    Degree>();
adj.
for (V vertice : adj.get(V)) {
    vertice.
}


 }



  }

我是通过移动设备发布的,但没有看到典型的格式代码标签。这是Degree课程:

   public class Degree {


//Number off incoming edges to a vertex
int indegree;

//number of outgoing edges from a vertex
int outdegree;

//Constructor
public Degree ( int indegree, int outdegree){

    this.indegree= indegree;
    this.outdegree= outdegree;
}


//Getter and Setter MNethods

public int getIndegree() {
    return indegree;
}

public void setIndegree(int indegree) {
    this.indegree = indegree;
}

public int getOutdegree() {
    return outdegree;
}

public void setOutdegree(int outdegree) {
    this.outdegree = outdegree;
}


   }

我的问题是到目前为止我在计算inoutdegrees的方法中究竟做错了什么。这真让我难以置信。

0 个答案:

没有答案