示例#1
0
void WeightedDigraph::addEdge(const DirectedEdge &e)
{
    if(e.from() >= V() || e.to() >= V())
        return;
    
    ++edgeCount;
    array[e.from()].push(e);
}
std::deque<DirectedEdge> *Djikstra::pathTo(int v){
    if(!hasPathTo(v))
         return 0;
    std::deque<DirectedEdge> *path =  new std::deque<DirectedEdge>();
    for(DirectedEdge e = edgeTo[v]; e.from() || e.to() || e.Getweight(); e =edgeTo[e.from()])
        path->push_front(e);
    return path;
}
std::deque<DirectedEdge> *BellmanFord::pathTo(int v){
    if(!hasPathTo(v))
        return 0;
    std::deque<DirectedEdge> *path = new std::deque<DirectedEdge>();
    for(DirectedEdge e = edgeTo[v];e.from() || e.to() || e.Getweight(); e=edgeTo[e.from()] ){
        int w = e.from();
        w++;w--;
        path->push_front(e);
    }
    return path;
}