forked from ongjinzen/social-network-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGraph.c
More file actions
107 lines (93 loc) · 2.06 KB
/
Copy pathtestGraph.c
File metadata and controls
107 lines (93 loc) · 2.06 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
#ifndef GRAPH
#define GRAPH
#include "Graph.h"
#endif
**/
#include "Graph.h"
#include "GraphVis.h"
#include "BSTree.h"
#include <stdlib.h>
#include <stdio.h>
void check_removeEdge_adjacent(Graph g);
void check_inIncident(Graph g);
void check_outIncident(Graph g);
void printSortedAdjList(AdjList list){
Tree t = newTree();
while(list != NULL) {
t = TreeInsert(t, list->w);
list = list->next;
}
printTree(t);
freeTree(t);
}
int main(int argc, char* argv[]){
Graph g = newGraph(10);
insertEdge(g,0,1,2);
insertEdge(g,0,2,5);
insertEdge(g,0,3,1);
insertEdge(g,1,4,1);
insertEdge(g,0,5,7);
insertEdge(g,1,6,2);
insertEdge(g,0,7,100);
insertEdge(g,2,8,3);
insertEdge(g,0,9,9);
insertEdge(g,9,0,11);
insertEdge(g,5,1,6);
insertEdge(g,9,4,2);
insertEdge(g,3,8,4);
insertEdge(g,8,1,8);
insertEdge(g,1,3,4);
insertEdge(g,7,5,2);
insertEdge(g,7,2,6);
check_removeEdge_adjacent(g);
check_inIncident(g);
check_outIncident(g);
printf("\n\n");
//graphVis(g, DEFAULT);
}
void check_removeEdge_adjacent(Graph g) {
printf("\nnV: %d\n",numVerticies(g));
printf("\n\n***** Check Adjacency...\n");
int i = 0;
int j = 0;
for (i=0;i<10;i++) {
for (j=0;j<10;j++) {
if (i == j) continue;
printf(" %d -> %d : %d\n",i,j,adjacent(g,i,j));
}
}
printf("Remove Edge 8->1\n");
removeEdge(g,8,1);
printf("Remove Edge 9->0\n");
removeEdge(g,9,0);
printf("Remove Edge 0->3\n");
removeEdge(g,0,3);
printf("\n\n***** Check Adjacency (after remove edge)...\n");
for (i=0;i<10;i++) {
for (j=0;j<10;j++) {
if (i == j) continue;
printf(" %d -> %d : %d\n",i,j,adjacent(g,i,j));
}
}
printf("\nnV: %d\n",numVerticies(g));
}
void check_outIncident(Graph g) {
printf("\n\n***** Check outIncident...\n");
int i = 0;
for (i=0;i<10;i++) {
printf(" %d : ",i);
printSortedAdjList( outIncident(g,i) );
printf("\n");
}
}
void check_inIncident(Graph g) {
printf("\n\n***** Check inIncident...\n");
int i = 0;
for (i=0;i<10;i++) {
printf(" %d : ",i);
AdjList l1 = inIncident(g,i);
printSortedAdjList( l1 );
printf("\n");
}
}