Scala: recursive search avoiding cycles

Posted by user1826663 on Stack Overflow See other posts from Stack Overflow or by user1826663
Published on 2012-12-08T10:40:16Z Indexed on 2012/12/08 11:05 UTC
Read the original article Hit count: 144

Filed under:
|
|

How can I write a recursive search that I avoid cycles.

My class is this:

class Component(var name: String, var number: Int, var subComponent: Set[Component])

Now I need a way to check whether a component is contained within its subcomponent or between subcomponent of its subcomponent and so on.Avoiding possible cycles caused by other Component.

My method of recursive search must have the following signature, where subC is the Set [component] of comp.

def content (comp: Component, subC: Set[Component]) : Boolean = {
}

Thanks for the help.

© Stack Overflow or respective owner

Related posts about scala

Related posts about search