1 /* The data structure/ ADT for the edge-list */
6 /*extern VerticesListType graph; */
8 void * InitEdgeList(int E
)
10 EdgeListType
* edgesRec
;
12 edgesRec
= (EdgeListType
*) malloc(sizeof(EdgeListType
));
15 edgesRec
->edges
= (Edge
*) malloc(E
*sizeof(Edge
));
16 _MEMCHECK(edgesRec
->edges
);
20 void addEdge(VerticesListType
*graph
, EdgeListType
* EdgeList
, int v
, int w
)
26 /* printf("adding edge: (%d, %d)\n", v, w); */
27 ((EdgeList
->edges
)[n
]).node1
= v
;
28 (EdgeList
->edges
[n
]).node2
= w
;
29 index
= graph
->vertexArray
[v
].next
++;
30 graph
->adjArray
[ index
] = w
;
31 index
= graph
->vertexArray
[w
].next
++;
32 graph
->adjArray
[ index
] = v
;
34 graph
->vertexArray
[v
].degree
++;
35 graph
->vertexArray
[w
].degree
++;
38 void printEdges(EdgeListType
*EdgeList
)
42 edges
= EdgeList
->edges
;
43 for (i
=0; i
< (EdgeList
->next
); i
++)
44 {printf("%d\t%d\n", edges
[i
].node1
, edges
[i
].node2
);
48 int edgeExists(VerticesListType
*graph
, int x
, int y
)
51 ind
= graph
->vertexArray
[x
].adjListInd
;
53 for(i
=0; i
< graph
->vertexArray
[x
].degree
; i
++)
54 { if (graph
->adjArray
[ind
+ i
] == y
) return 1;}
60 If we are adding an edge between two nodes already connected then we
61 need special changes. We open some distinct edge say x,y and
62 connect v with y and x with w
65 void addspEdge(VerticesListType
*graph
, EdgeListType
* EdgeList
, int v
, int w
)
67 int n
, index
,i
,x
,y
,ind
;
71 /* printf("adding edge: (%d, %d)\n", v, w); */
72 /*((EdgeList->edges)[n]).node1 = v;*/
73 /*(EdgeList->edges[n]).node2 = w;*/
75 if (((EdgeList
->edges
[i
]).node1
!=v
) && ((EdgeList
->edges
[i
]).node2
!=w
))
77 x
=(EdgeList
->edges
[i
]).node1
;
78 y
=(EdgeList
->edges
[i
]).node2
;
79 (EdgeList
->edges
[i
]).node2
=w
;
80 (EdgeList
->edges
[n
]).node1
=v
;
81 (EdgeList
->edges
[n
]).node2
=y
;
84 ind
= graph
->vertexArray
[x
].adjListInd
;
85 for(i
=0; i
< graph
->vertexArray
[x
].degree
; i
++)
86 { if (graph
->adjArray
[ind
+ i
] == y
) graph
->adjArray
[ind
+i
]=w
;}
88 ind
= graph
->vertexArray
[y
].adjListInd
;
89 for(i
=0; i
< graph
->vertexArray
[y
].degree
; i
++)
90 { if (graph
->adjArray
[ind
+ i
] == x
) graph
->adjArray
[ind
+i
]=y
;}
92 index
= graph
->vertexArray
[v
].next
++;
93 graph
->adjArray
[ index
] = y
;
94 index
= graph
->vertexArray
[w
].next
++;
95 graph
->adjArray
[ index
] = x
;
96 graph
->vertexArray
[v
].degree
++;
97 graph
->vertexArray
[w
].degree
++;