ch.bfh.algo.example
Class GraphExample2
java.lang.Object
ch.bfh.algo.example.GraphExample2
public class GraphExample2
- extends Object
The class GraphExample2
contains an example of the
ch.bfh.algo.Graph
interface, using the Factory Pattern
to have specialized Vertices.
This example contains the creation of one graph containing 10
vertices and 12 edges. The vertices have two new properties visited
which is used durring the algorithm and
connectedComponentNumber
which contains the number of
the connencted component containing this vertex. They are
implemented using another class and the Factory Pattern to create
new instances without changing anything in the graph classes.
- Version:
- 1.0
- Author:
- Emmanuel Benoist
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GraphExample2
public GraphExample2()
bfsTraversal
public static Sequence<Position<String>> bfsTraversal(Graph<Integer,String> g)
- The
bfsTraversal
is an example of the possible
implementation of a Breadth First Search traversal of a
Graph
. In this case, we use the
DecoratedVertex
to store inside each vertex if it
has been visited.
- Returns:
- a
Sequence
value
constructUndirectedGraph
public Graph<Integer,String> constructUndirectedGraph()
- The
constructUndirectedGraph
method is used to
initialize a default undirected Graph
.
The returned graph contains 10 vertices and 12 edges.
- Returns:
- a
Graph
value
run
public void run()
main
public static void main(String[] args)