Scott Dabot wrote:[color=blue]
> I am trying to write a program that uses graphs and I have this
> algorithm for the Depth First Search.
>
> //Input: Graph G=(V, E)
> //Output Graph G with its vertices marked with consecutive integers in
> //the order they've been first encountered by the DFS traversal mark
> //each vertex in V with 0 as a mark of being "unvisited"
>
> count<--0
>
> for each vertex v in V do
> if v is marked with 0 dfs(v)
>
>
> algorithm for dfs
> //visits recursively all the unvisited vertices connected to vertex v
> and then assigns them the numers in the order they are encountered via
> global variable count
>
> count<-- count +1; mark v with count
>
> for each vertex w in V adjacent to v do
> if w is marked with 0
> dfs(w)
>
> My question is the first algorithm DFS(G), takes in a graph , and then
> says a Graph is G(V,E)... What type of data structure is a graph, that u
> can pass it in as a Graph and then it has a V(vertice) and E ( edge). I
> also have the algorithm for the BFS but it takes in a Graph too. I do
> not know exactly what a Graph data structure is so therefore i can't use
> the algorithm. Any help is greatly appreciated.[/color]
A graph is a set of nodes and vertices. If you don't care about
performance, just write a linked list of nodes:
typedef struct _node{
void *data;
void *vertex_list;
void *next_node;
} node;
typedef struct _graph{
node* first;
node* last;
}
--
Thanks,
Elliott C. Bäck
--------------------------
www.elliottback.com www.spreadIE.com