-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjoinmatrix.c
59 lines (52 loc) · 962 Bytes
/
adjoinmatrix.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>
#define MaxvertexNum 100
typedef char VertexType;
typedef int EdgeType;
typedef struct MGraph
{
VertexType vexs[MaxvertexNum];
EdgeType edges[MaxvertexNum][MaxvertexNum];
int n, e;
}MGraph;
MGraph * CreateMGraph()
{
int i, j, k, w;
MGraph *G = (MGraph *)malloc(sizeof(MGraph));
printf("please input data of vertex and edge num with blank \n ");
scanf_s("%d %d",&G->n,&G->e);
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++)
{
printf("please input data of v-e with weight\n ");
scanf_s("%d%d%d", &i, &j, &w);
G->edges[i][j] = w;
G->edges[j][i] = w;
}
return G;
}
void Show(MGraph *G)
{
for (int i = 0; i < G->n; i++)
{
for (int j = 0; j < G->n; j++)
{
printf("%d\t", G->edges[i][j]);
}
printf("\n");
}
printf("\n");
}
void main()
{
MGraph * M=CreateMGraph();
Show(M);
system("pause");
}