File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes find path in a graph Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Other » Programming Diversions
Reply locked New topic
Author

find path in a graph

Neo Milton
Greenhorn

Joined: Jun 22, 2004
Posts: 2
I have a graph which is representet by some nodes and edges. An edge is a pair of nodes SML code)

val n1 = Node("London");
val n2 = Node("Paris");
val n3 = Node("Berlin");

val e1 = Edge(n1,n2);
val e1 = Edge(n2,n3);

val edges = (e1,e2) (* this is the graph *)

I need a function to tell my wether there is a path from node x to node y.
How can I build such a function without use of for and while loops?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923



val e1 = Edge(n1,n2);
val e1 = Edge(n2,n3);

val edges = (e1,e2) (* this is the graph *)

I need a function to tell my wether there is a path from node x to node y.

shouldn't it be
val e2 = Edge(n2,n3);
and
... a path from node n1 to n3?

I don't know SML-Code,
And whether 'val' has a special meaning here.

I immediately think of recursion...


http://home.arcor.de/hirnstrom/bewerbung
Neo Milton
Greenhorn

Joined: Jun 22, 2004
Posts: 2
"val n = .." is the same as "var n = .." in javascript.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Hello The scrap,

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.

Also this forum is not meant to solve your problems!

Thanks,
Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: find path in a graph