我正在實現一些算法來教我自己關於圖的方法以及如何使用它們。你會推薦什麼是在Java中做到這一點的最佳方式?有向圖和無向圖 - Java
我只是想問你,如果你能給出一個簡短的幫助很簡單的類定義有向圖和加權有向圖嗎?
我查看了網頁,但我不想要它的實現,只是類的簡短定義....你認爲是最好的數據結構使用?相鄰列表?
對於無向圖我把它定義爲如下:
public interface Graph {
Collection vertices(); // returns a collection of all the
// Vertex objects in the graph
Collection edges(); // returns a collection of all the
// Edge objects in the graph
Collection incidentEdges(Vertex v); // returns a collection of
// Edges incident to v
boolean isAdjacent(Vertex v, Vertex w); // return true if v and
} // w are adjacent
public class Vertex {
public boolean visited; // initially false for all vertices
}
public class Edge {
Vertex v1, v2; // undirected edge
Vertex opposite(Vertex v); // given a vertex return the one
} // at the other end of this edge
[有向圖的數據結構允許快速節點刪除?]的可能的副本(http://stackoverflow.com/questions/5084421/data-structure-for-directed-graphs-allowing-fast-node-deletion) – Perception 2013-02-17 12:37:33