#pragma hdrstop
#include #include #define MAXLEN 1000
int cost[7][7];
int dist[7];
//-------------------------------------------------------------------
#pragma argsused void creategraph(int *node,int num)
{
int from;
int to;
int i;
for ( i = 0; i < num; i )
{
from = node[i*3];
to = node[i*3 1];
cost[from][to] = node[i*3 2];
}
} void shortestpath(int begin,int num)
{
int selected[7];
int min;
int s;
int i,j; for ( i = 2; i <= num; i )
{
selected[i] = 0;
dist[i] = cost[begin][i];
}
selected[begin] = 1;
dist[begin] = 0;
printf("頂點1 2 3 4 5 6\n"); for ( j = 1; j <= num; j )
printf(" M ",dist[j]);
printf("\n"); for ( i = 1; i <= num - 1; i )
{
min = MAXLEN;
for ( j = 1; j <= num; j ) if ( min > dist[j] && selected[j] == 0 )
{
s = j;
min = dist[j];
}
selected[s] = 1; for ( j = 1; j <= num; j )
{
if (selected[j] == 0 && dist[s] cost[s][j] < dist[j])
dist[j] = dist[s] cost[s][j];
printf(" M ",dist[j]);
}
printf("\n");
}
} //---------------------------------------------------------
int main(int argc, char* argv[])
{
int i,j,q;
int Array[2]
Array[0]=end_x-x;
Array[0]=end_y-y;
int Dist=judge(end_x-x,end_y-y)
int node[7][3] = {{1, 2, 35},
{2, 3, 45},
{2, 4, 30},
{3, 5, 25},
{4, 5, 45},
{4, 6, 130},
{5, 6, 100}}; for ( i = 1; i <= 6; i )
for ( j = 1; j <= 6; j )
cost[i][j] = MAXLEN;
creategraph(*node,7);
printf("加權圖形的鄰接陣列內容:\n");
for ( i = 1; i <= 6; i )
{
for ( j = 1; j <= 6; j )
printf(" M ",cost[i][j]);
printf("\n");
}
printf("\n從頂點1到各頂點最近距離計算過程:\n");
shortestpath(1,6);
return 0; } 請問各位大大~~我想將上面的程式改成~~矩陣可以自己輸入 而計算之結果能在memo上輸出 矩陣輸入方面~是要怎麼寫呢?如果我要用寫( "輸入資料","資料",""); 是要如何判斷是陣列呢?