Reputation: 31
I have some trouble with building Graph Structure. I know how to build a simply linked list and doubly too. But I want to construct a graph structure like in this site (the pic. output) http://www.cs.sunysb.edu/~algorith/files/graph-data-structures.shtml
Upvotes: 1
Views: 2153
Reputation: 133577
You have three common solutions:
N*N
where N is the number of vertices and in matrix[x][y]
you will store a value if x
has an edge to y
, 0 otherwise(x,y)
is in the list, then there is an edge from x to yx
has a list of edges to the nodes for which x has an edge to.Every different approach is good or bad according to
So according to what you need to do with the graph you could choose any of those. If you want to know specific characteristic of the above possible implementations take a look at my answer to another SO question.
Upvotes: 2