By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,191 Members | 739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,191 IT Pros & Developers. It's quick & easy.

any info on graphs algorithms examples ?

P: n/a
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
Jun 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
johnny wrote:
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

Jun 19 '06 #2

P: n/a
Robert Gamble wrote:
johnny wrote:
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.


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

--
"I don't know where bin Laden is. I have no idea and really
don't care. It's not that important." - G.W. Bush, 2002-03-13
"No, we've had no evidence that Saddam Hussein was involved
with September the 11th." - George Walker Bush 2003-09-17
Jun 19 '06 #3

P: n/a
CBFalconer wrote:
Robert Gamble wrote:
johnny wrote:
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.


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

Jun 19 '06 #4

P: n/a

"johnny" <a@a.com> wrote in message
news:e7**********@nsnmrro2-gest.nuria.telefonica-data.net...
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.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
Jun 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.