any info on graphs algorithms examples ?

J

johnny

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 ???

Tna
Johnny
 
R

Robert Gamble

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 ???

Algorithms in C Parts 1-5 by Robert Sedgewick, Part 5 consists of its
own volume dedicated to graphing algorithms and their implementations
in C.

You could try searching google as well.

Robert Gamble
 
C

CBFalconer

Robert said:
Algorithms in C Parts 1-5 by Robert Sedgewick, Part 5 consists of its
own volume dedicated to graphing algorithms and their implementations
in C.

In my copy it is chapters 29 thru 34. ISBN 0-201-51425-7, 1990.
 
R

Robert Gamble

CBFalconer said:
In my copy it is chapters 29 thru 34. ISBN 0-201-51425-7, 1990.

I was referring to the 3rd edition, I guess I should have mentioned
that.

Robert Gamble
 
M

Malcolm

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top