Bookmark Topic Watch Topic
  • New Topic

find path in a graph

 
Neo Milton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Report post to moderator


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...
 
Neo Milton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
"val n = .." is the same as "var n = .." in javascript.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic