何よりもまず、私はモバイル デバイスを使用しているため、通常の編集オプションが利用できないため、見栄えがよくない可能性があります。入次数と出次数を見つける方法について少し混乱しています。これは 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 を計算する方法で、これまでのところ何が間違っているのかということです。それは本当に私の心を揺さぶっています。