1 回答
TA贡献1811条经验 获得超4个赞
是这个意思吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <stdlib.h> #include <iostream> #define OK 1 #define MVNum 3 typedef int Status; typedef char VerTexType; typedef int ArcType; struct edge//(结构) { VerTexType adjvex; //最小边的顶点 ArcType lowcost; //最小边的权值 }closedge[ MVNum ]; //辅助数组
Status Min() { int N,x,min=closedge[1].lowcost; for( x = 1; x < MVNum; x++) { if(min > closedge[x].lowcost) min = closedge[x].lowcost;//找closedge数组中权值最小的那组 N = x;//N保存权值最小的那组的下标 } std::cout<<N;//输出最小权值对应的那组数组的下标 return OK; }
int main(void) { closedge[0].adjvex = 'A'; closedge[0].lowcost = 3; closedge[1].adjvex = 'B'; closedge[1].lowcost = 2; closedge[2].adjvex = 'C'; closedge[2].lowcost = 1; Min(); getchar(); getchar(); return 0;
} |
- 1 回答
- 0 关注
- 830 浏览
添加回答
举报