johnny said:
I am looking onto some C examples about graphs: implementation with
adjacent matriz or with linked list, and how can I visit the vertex.
Any sample code ???
You really want comp.programming.
In C, it is easy to build complex data structures like graphs with
structures containing pointers.
eg
typedef struct Vertex_tag
{
int Nneighbours;
struct Vertex_tag **neighbour;
void *userdata;
} Vertex;
The slightly unusual Vertex_tag construction is to get round a problem with
recursive typedefs. The neightbour member is a list of pointers, allocated
with malloc(), and Nneighbours is self-explanatory.
The other way would be to have an adjaceny matrix
int *adjmatrix = malloc(N * N);
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(adjacent(i,j))
adjmatrix[i*N+j] = 1;
else
adjmatrix[i*N+j] = 0;
This suffers from the problem that C syntax for 2 d arrays is very difficult
to use, hence we are simply doing the array indexing by hand.
Which method you use won't be dictated by language considerations, however,
but what makes sense in terms of the particular algorithm you are trying to
implement.