图遍历及其算法模板

1.算法模板:

public class GraphTrverse {

    final  static int undiscoeverd=0;
    final static int discovered=1;
    final static int visited=2;
    final static int unknown=0;

    final static int tree=1;
    final static int  CROSS=2;
    final  static int forward=3;
    final static  int backward=4;

    //变量
    protected  Graph G;

    public GraphTrverse(Graph g) {
        G = g;
    }


    protected  void reset(Vertex s){
        for(Iterator it=G.vertices();it.hasNext()){
            Vertex v=(Vertex)  it.Next();
            v.setStatus(UNDISCOVERED);
            v.setDistance(Inter.MAX_VALUE);
        }

        for(Iterator it=G.edges();it.hasNext()){
            ((Edge) it.getNext()).setType(UNKNOWN);
        }
    }

    //遍历过程中对定点的v 的具体操作的模板,取决与,服务于就见图的算法algorithm()
    protected  abstract Object algorithm(Vertex s,Object info);

    //遍历算法模板
    protected  abstract  Object traverse(Vertex v,Object info);

    //遍历算法模板
    protected abstract Object traverse(Vertex v,Object info);





}

 

    原文作者:数据结构之图
    原文地址: https://blog.csdn.net/xiamaocheng/article/details/83958340
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞