scala - Finding node in tree -


i have tree can have multiple root nodes. node defined as:

case class node[a] ( id: int, data: a, var children: option[seq[node[a]]],                          var parent: option[node[a]] )  

where id identifies node, data information related node, children sequence of nodes, , parent points parent node.

the tree class follows:

case class tree[a] ( var nodes: option[seq[node[a]]] ) {        def searchparent (searchid: int): option[node[a]] = {           nodes match {               case some(nodes) => {                   ( node <- nodes ) {                     val parent = searchparent2(node,searchid)                     parent match {                       case some(p) => {                         parent                       }                       case none => none                     }                   }                   none               }               case none => none             }       }        def searchparent2 (node: node[a], searchid: int): option[node[a]] = {             node.children match {               case some(nodes2) => {                   ( node2 <- nodes2 ) {                     if (node2.id == searchid)                       some(node2)                     else                       searchparent2(node2,searchid)                   }                   none               }               case none => none             }      }  } 

problem when search node based on id, none. what's wrong code?


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -