Giriş
Şu satırı dahil ederiz.
nodeOrder metodu - ElementOrder.insertionŞu satırı dahil ederiz.
import com.google.common.graph.ElementOrder;
import com.google.common.graph.Graph;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.Traverser;
MutableGraph nesneyi yaratmak için kullanılır
directed metodu
Şöyle yaparız
//graph of IntegersMutableGraph<Integer> myGraph= GraphBuilder.directed().build();//graph of StringsMutableGraph<String> myGraph= GraphBuilder.directed().build();//graph of any classesMutableGraph<MyCustomClassInstance> myGraph= GraphBuilder.directed().build();
Açıklaması şöyle. Düğümleri eklendikleri sırada dolaşabilme imkanı sağlar.
Graph stores nodes in map under the hood, and for ElementOrder.insertion() it's LinkedHashMap. For Graph#nodes() keySet() of such map is used, so there's no better way to fetch last value other than iterating over all elements and returning the last one.Şöyle yaparız.
MutableGraph<Integer> subgraph = GraphBuilder.undirected()
.nodeOrder(ElementOrder.insertion())
.build();
putEdge metoduÖrnek
Şöyle yaparız
Node root = new Node("root");
Graph<Node> graph = GraphBuilder.directed()
.nodeOrder(ElementOrder.insertion())
.<Node>immutable()
.putEdge(root, new Node("one"))
.putEdge(root, new Node("two"))
.putEdge(root, new Node("three"))
.build();
//Print the nodes in traversal order.
Traverser.forGraph(graph).depthFirstPostOrder(root)
.forEach(x->System.out.println(x));
Hiç yorum yok:
Yorum Gönder