I have two trees (paths), defined by a node like
trait Node {
def getParent : Node
def op(n:Node)
}
and I want to travel two nodes up until the parent is null in parallel like:
Pseudo:
def simultanousUp(/*var*/ a:Node,/*var*/ b:Node) =
while(a != null) {
a.op(b);
a = a.getParent;
b = if(b!=null) b.getParent else null /*or throw somthing*/;
}
Question: is there a more elegant and/or performant way in scala to do this?
To avoid misunderstandings: its not a question about concurrent execution!
1 Answer