1

首先,我在移动设备上,所以这可能看起来不太漂亮,因为典型的编辑选项不可用。我对如何查找入度和出度有点困惑。这是由 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.
}


 }



  }

我是从移动设备上发布的,没有看到典型的格式代码标签。这是学位课程:

   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 的方法中到底做错了什么。这真的让我大吃一惊。

4

0 回答 0