score:0

One way is to define an inner function with a visited accumulator.

def content (comp: Component, subC: Set[Component]) : Boolean = {
    def contained(comp: Component, subC: Set[Component], visited: Set[Component]): Boolean = {
        // over time (recursion) add components to visited
        // you can then use 
        //    visited contains comp
        // to check existence and 
        //    visited diff subC
        // to get the unvisited components

    }
}

score:0

The simplest way to implement this is to keep a set of visited components. This can be defined as a method inside your method. The method will do the recursion. It will take the visited set as an extra argument and will be initiated with an empty set.


Related Query

More Query from same tag