for (int i = 1; i <= G.vexnum; i++) { closeedges[i].end_ver = 1; closeedges[i].lowcost = G.arcs[1][i]; closeedges[i].flag = 0; } closeedges[1].flag = 1; int min; for (int i = 2; i <= G.vexnum; i++) { min = -1; for (int j = 1; j <= G.vexnum; j++) { if (closeedges[j].flag == 0 && (closeedges[j].lowcost > 0 && (min < 0 || closeedges[min].lowcost>closeedges[j].lowcost))) min = j; } closeedges[min].flag = 1; setlinecolor(GREEN); setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 5); draw_arc(G.vexs[closeedges[min].end_ver], G.vexs[min], closeedges[min].lowcost); setlinecolor(RED); setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 1); setfillcolor(MAGENTA); for (int i = 1; i <= G.vexnum; i++) { draw_vex(G.vexs[i], i); } Sleep(1000); for (int j = 2; j <= G.vexnum; j++) { if (closeedges[j].flag == 0 && (G.arcs[j][min] > 0 && (closeedges[j].lowcost < 0 || closeedges[j].lowcost > G.arcs[j][min]))) { closeedges[j].end_ver = min; closeedges[j].lowcost = G.arcs[j][min];
时间: 2023-03-14 19:20:45 浏览: 87
数据结构课程设计 最小生成树
为每个顶点i,将closeedges[i].end_ver设为1,closeedges[i].lowcost设为G.arcs[1][i],closeedges[i].flag设为0;将closeedges[1].flag设为1;循环遍历每个顶点,找出最小的closeedges[j].lowcost,将其flag设为1,并将min设为j。
阅读全文