Curriculum design of Campus Guide map (III.)

Source: Internet
Author: User

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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.