1 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
是這個(gè)意思嗎?
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//(結(jié)構(gòu)) { VerTexType adjvex; //最小邊的頂點(diǎn) ArcType lowcost; //最小邊的權(quán)值 }closedge[ MVNum ]; //輔助數(shù)組
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數(shù)組中權(quán)值最小的那組 N = x;//N保存權(quán)值最小的那組的下標(biāo) } std::cout<<N;//輸出最小權(quán)值對(duì)應(yīng)的那組數(shù)組的下標(biāo) 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 關(guān)注
- 866 瀏覽
添加回答
舉報(bào)