I would suggest your adjacency list datastructure be implemented
something like:
[ (A, [B, C], [D, E]),
(B, [], [A]),
(C, [D], [A]),
(D, [A], [C])
(E, [A], [])
]
Notice how each vertex in parens () has two lists. One for outgoing
edges, and one for incoming edges.
This comes from graph:
A B
A C
C D
D A
E A
You now have access to the incoming and outgoing edges of each vertex.
I do not recommend keeping an undirected graph next to the other graph.
-Robert
-Nikos
Here's how I merge incoming and outgoing edges:
m = hashmap from (int, int) to int
for each vertex:
for each incoming edge from, to, weight:
if from < to:
add (from, to) -> weight to hashmap (making sure to account
for the possibility that it exists).
else:
add (to, from) -> weight in the same way as the above.
do the same for the outgoing edges of the vertex
Convert m to a sorted array.
-Robert
hashcode() and equals() need to be implemented appropriately for the pair.
-Nikos