Hi all,

I need to utilize a Graph Data structure for an assignment. I've understood the following code (posted below) until I came to the search function. The depthFirstSearch and breadthFirstSearch both require a Visitor<T> which is an interface. I'm not much used to interfaces, so I'm not sure where to start in utilizing these functions.

If someone could help me understand how I can build an interface that implements Visitor, it would be much appreciated.

depthFirstSearch function

   public <E extends Exception> void depthFirstSearch(Vertex<T> v, VisitorEX<T, E> visitor) throws E{
       if( visitor != null ){
         visitor.visit(this, v);   
  for (int i = 0; i < v.getOutgoingEdgeCount(); i++) {
     Edge<T> e = v.getOutgoingEdge(i);
     if (!e.getTo().visited()){
        depthFirstSearch(e.getTo(), visitor);

Visitor Interface

interface Visitor<T> {

  public void visit(Graph<T> g, Vertex<T> v);

 interface VisitorEX<T, E extends Exception> {

    public void visit(Graph<T> g, Vertex<T> v) throws E;

Thanks in advance

5 Years
Discussion Span
Last Post by Dmiller071

For some examples look at the API doc for java.util.List (an interface) and then at a class that implements it: ArrayList

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.