void dijkstra(Digraph G, Vertex s){ Vertex v, w; link p; for (v = 0; v < G->V; v++) { cst[v] = INFINITO; parnt[v] = -1; } PQinit(G->V); cst[s] = 0; parnt[s] = s; PQinsert(s); while (!PQempty()) { v = PQdelmin(); for(p=G->adj[v];p!=NULL;p=p->next) if(cst[w=p->w]==INFINITO){ cst[w]=cst[v]+p->cst; parnt[w]=v; PQinsert(w); }else if(cst[w]>cst[v]+p->cst){ cst[w]=cst[v]+p->cst; parnt[w] = v; PQdec(w); } } PQfree(); }
void GRAPHpfs(Graph G, int st[], double wt[]) { link t; int v, w; PQinit(); priority = wt; for (v = 0; v < G->V; v++){ st[v] = -1; fr[v] = -1; } fr[0] = 0; PQinsert(0); while (!PQempty()) { v = PQdelmin(); st[v] = fr[v]; for (t = G->adj[v]; t != NULL; t = t->next) if (fr[w = t->v] == -1){ wt[w] = P; PQinsert(w); fr[w] = v; } else if ((st[w] == -1) && (P < wt[w])){ wt[w] = P; PQdec(w); fr[w] = v; } } }
void GRAPHmstP2 (Graph G, Vertex parnt[], double cst[]) { Vertex v, w, fr[maxV]; link p; GRAPHmaxcst(G); for (v = 0; v < G->V; v++) { cst[v] = INFINITO; parnt[v] = -1; } PQinit(G->V); cst[0] = 0; fr[0] = 0; PQinsert(0); while (!PQempty()) { v = PQdelmin(cst); parnt[v] = fr[v]; for (p=G->adj[v];p!=NULL;p=p->next){ w = p->w; if (parnt[w] == -1){ if (cst[w] == INFINITO){ cst[w] = p->cst; fr[w] = v; PQinsert(w); } else if (cst[w] > p->cst){ cst[w] = p->cst; fr[w] = v; } } } } }
void GRAPHpfs(Tree T, int s, int *st, double *wt){ int v, w; link t; struct fibheap *pq; pq = fh_makeheap(); fh_setcmp(pq, wt_cmp); /* PQinit(); */ /* priority = wt; */ for (v = 0; v < G->V; v++) { st[v] = -1; wt[v] = Inf; PQinsert(v); } wt[s] = 0.0; PQdec(s); while (!PQempty()) if (wt[v = PQdelmin()] != maxWT) for (t = G->adj[v]; t != NULL; t = t->next) if (P < wt[w = t->v]){ wt[w] = P; PQdec(w); st[w] = v; } }