我使用Guava Graph 库有这个直截了当的Graph 结构,如果可以对(而不是顺序)进行排序,我想更好地理解。为了澄清:adjacents/edges
node
import com.google.common.graph.ElementOrder;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
public class MyNodeTest {
public static void main(String[] args) {
MutableGraph<String> graph = GraphBuilder.undirected().nodeOrder(ElementOrder.insertion()).build();
graph.addNode("A");
graph.addNode("C");
graph.addNode("D");
graph.addNode("B");
graph.addNode("E");
graph.putEdge("A", "B");
graph.putEdge("A", "C");
graph.putEdge("A", "D");
graph.putEdge("A", "E");
System.out.println("My default Insertion.order Nodes: " + graph.nodes());
System.out.println("Adj. Order that I couldn't understand: " + graph.adjacentNodes("A"));
System.out.println("Successor. Order that I couldn't understand: " + graph.successors("A"));
System.out.println("Pred. Order that I couldn't understand: " + graph.predecessors("A"));
}
}
我的结果是:
My default Insertion.order Nodes: [A, C, D, B, E]
Adj. Order that I couldn't understand: [D, E, B, C]
Successor. Order that I couldn't understand: [D, E, B, C]
Pred. Order that I couldn't understand: [D, E, B, C]
废话不多说,我的意思是:
使用.nodeOrder(ElementOrder.insertion())
它可以对节点本身进行排序。尽管如此,我对edges
与给定关联的排序node
方式更感兴趣,如果我putEdge
分别使用 fromA
与B, C, D, E
结果正是这个而不是上面显示的。
有什么见解吗?
提前致谢。