Two days and a day.
As long as the implementation of the prime algorithm, the role is to find a graph of the smallest spanning tree, with a list
void Prim (Listmatrix *g, int start)/* * Find a point for the best cabling for the core * that is, using the prime minimum spanning tree */{struct{int adjvex; int lowcost; }closedge[nummax]; int i,j,k,m,min; Arcnode * p; Closedge[start].lowcost = 0; for (I=1; i<=g->vexnum; i++) {if (i! = start) {C Losedge[i].adjvex = start; Closedge[i].lowcost = infnity; }}//initialized, infinity p = g->vertex[start].next; while (P! = NULL) {closedge[p->adjvex].lowcost = p->weight; p = p->next; }//copy for (j=1; j<=g->vexnum; J + +) {min = infnity; for (k=1; k<=g->vexnum; k++) {if (closedge[k].lowcost!=0 && close Dge[k].lowcost < min) { m = k; min = closedge[k].lowcost; }}//Pick the smallest closedge[m].lowcost = 0; p = g->vertex[m].next; while (P! = NULL) {if (P->weight < closedge[p->adjvex].lowcost) {closedge[p->adjvex].lowcost = p->weight; Closedge[p->adjvex].adjvex = m; } p = p->next; }//while find the shortened} printf ("\t\t\t\t\t\t\t cabling method: \ n"); for (I=1; i<=g->vexnum; i++) {if (i!= start) {print F ("\t\t\t\t\t\t\t%d from%d:%s to%d:%s\n", I,closedge[i].adjvex, Numtoname (g,closedge[i].adjve x), I,numtoname (g,i)); } } }
The core of the prime algorithm looks for a shortest path between the V and V-s sets, placing the v-s head of the path in the V-set, in the next step, until the end.
There is also the deletion and addition of nodes, the addition and deletion of arcs
The idea of removing the M-node:
Delete the arc connected to it
Remove the M node and move the subsequent nodes forward
Traverse all arcs, point the Arc tail node greater than M, subtract one
Complete
Curriculum design of Campus Guide map (III.)