Tuesday, May 8, 2012

A bothersome search function on Java multi tree

there is a multi-tree like this?



abc--xx       abc(have 3 children)
xv--yg xv(have 2 children)
ld
xu--ph
ld xu(have 2 children)


design a search function like: search(String key)



search("ld")
the result will be?(need the path from root to the result node)



abc--xv--ld
xu--ld


There is a TreeNode object (you can add your fields if you need)



    TreeNode{
string key;
List<TreeNode> children;
}




No comments:

Post a Comment