0001 template <typename Tv, typename Te> struct BfsPU { //针对BFS算法的顶点优先级更新器 0002 virtual void operator() ( Graph<Tv, Te>* g, int uk, int v ) { 0003 if ( g->status ( v ) == UNDISCOVERED ) //对于uk每一尚未被发现的邻接顶点v 0004 if ( g->priority ( v ) > g->priority ( uk ) + 1 ) { //将其到起点的距离作为优先级数 0005 g->priority ( v ) = g->priority ( uk ) + 1; //更新优先级(数) 0006 g->parent ( v ) = uk; //更新父节点 0007 } //如此效果等同于,先被发现者优先 0008 } 0009 };