?? 9-1.c
字號:
#include "stdio.h"
#define MaxVertexNum 100 /*最大頂點數,應由用戶定義*/
typedef char VertexType; /*頂點類型應由用戶定義*/
typedef int EdgeType; /*邊上的權值類型應由用戶定義*/
typedef struct Gragh{
VertexType vexs[MaxVertexNum];/*頂點表*/
EdgeType edges[MaxVertexNum][MaxVertexNum];
/*鄰接矩陣,可看作邊表*/
int n,e; /*圖中當前的頂點數和邊數*/
}Graphic;
void CreateMGraph(Graphic *G)
{/*建立無向網的鄰接矩陣表示*/
int i,j,k,w;
scanf("%d%d",&G->n,&G->e); /*輸入頂點數和邊數*/
for(i=0;i<G->n;i++) /*讀人頂點信息,建立頂點表*/
G->vexs[i]=getchar();
for(i=0;i<G->n;i++)
for(j=0;j<G->n;j++)
G->edges[i][j]=0; /*鄰接矩陣初始化*/
for(k=0;k<G->e;k++)
{/*讀入e條邊,建立鄰接矩陣*/
scanf("%d%d%d",&i,&j,&w);/*輸入邊(vi,vj)上的權w*/
G->edges[i][j]=w;
G->edges[j][i]=w;
}
}
void main(void)
{
Graphic Create;
CreateMGraph(&Create);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -