-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
70 lines (61 loc) · 1.66 KB
/
main.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
63
64
65
66
67
68
69
70
#include <stdio.h>
#include "graph_adapter.h"
#include "graph_reader.h"
void printEdgeList(struct TGEdgeList *edges);
void printAdjMatrix(struct TGAdjacencyMatrix *mtx);
int case1()
{
struct TGEdgeList* edges, *e2;
FILE *in = fopen("../in.txt", "r");
edges = readTGEdgeList(in);
fclose(in);
printEdgeList(edges);
struct TGAdjacencyMatrix* mtx = constructTGAMatrix(edges), *m2;
printf("\n");
printAdjMatrix(mtx);
e2 = constructTGEdgeList(mtx);
printf("\n");
printEdgeList(e2);
m2 = constructTGAMatrix(e2);
printf("\n");
printAdjMatrix(m2);
}
int case2()
{
printf("\n=====CASE 2======\n");
struct TGEdgeList* edges, *e2;
FILE *in = fopen("../inmtx.txt", "r");
struct TGAdjacencyMatrix* mtx = readTGAMatrix(in), *m2;
fclose(in);
printf("\n");
printAdjMatrix(mtx);
e2 = constructTGEdgeList(mtx);
printf("\n");
printEdgeList(e2);
m2 = constructTGAMatrix(e2);
printf("\n");
printAdjMatrix(m2);
}
int main() {
case1();
case2();
return 0;
}
void printAdjMatrix(struct TGAdjacencyMatrix *mtx) {
printf("%d\n", mtx->node_count);
int* mtx_end = mtx->mtx_data+mtx->node_count*mtx->node_count;
for (int* i = mtx->mtx_data; i < mtx_end; ++i) {
if ((i != mtx->mtx_data) && (i - mtx->mtx_data) % mtx->node_count == 0)
printf("\n");
printf("%d ", *i);
}
printf("\n");
}
void printEdgeList(struct TGEdgeList *edges) {
struct TGEdge* curr = edges->edges;
printf("%d\n", edges->edge_count);
for (int i = 0; i < edges->edge_count; ++i) {
printf("%d %d %d \n", curr->node1, curr->node2, curr->weight);
curr++;
}
}