-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist_mat.c
62 lines (58 loc) · 1.24 KB
/
dist_mat.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
60
61
62
#include<stdio.h>
#include<stdlib.h>
#include"header.h"
#include"cc.h"
float** sum;
float** sum_mat(int ver)
{
sum =(float**)malloc(ver*sizeof(float*));
for(int q=0;q<ver;q++)
{
sum[q] = (float*)calloc(ver,sizeof(float));
}
return sum;
}
int** dist_mat(struct graph* graph,char* filename,int c)
{
int **adj,*ptr,len,ver;
struct node* pt;
ver = graph->no_vertices;
len = sizeof(int*)*ver + sizeof(int)*ver*ver;
adj = (int**)malloc(len);
ptr = (int*)(adj+ver);
for(int p=0;p<ver;p++)
{
adj[p] = (ptr + ver*p);
}
for(int i=0;i<ver;i++)
{
for(int j=0;j<ver;j++)
{
if(i==j)
{
adj[i][j] = 0;
}
else
{
adj[i][j]=INF;
if(c==1)
{
sum[i][j]=1;
}
}
}
}
int ver_1,ver_2;
FILE *f = fopen(filename,"r");
for(int i=0;i<graph->no_vertices;i++)
{
for(int j=0;j<graph->no_vertices;j++)
{
fscanf(f,"%d %d %*d",&ver_1,&ver_2);
adj[ver_1][ver_2] = 1;
adj[ver_2][ver_1] = 1;
}
}
fclose(f);
return adj;
}