[Haskell-beginners] Does Haskell have a function that creates a list corresponding to the nodes in a tree, from the leaf node to the root node?
KC
kc1956 at gmail.com
Mon Jun 13 03:02:10 CEST 2011
Hi Roger:
It depends on what kind of tree you have and what kind of information
you expect to give the tree to find the leaf node.
If it's a binary search tree (BST) and you have the leaf key value
then use "find leafKey" and keep prepending the nodes you visit to the
list.
I might call the function: parents or ancestors. :)
On Sat, Jun 11, 2011 at 5:28 AM, Costello, Roger L. <costello at mitre.org> wrote:
> Hi Folks,
>
> I am implementing the following function in another language. I want to see if Haskell already has a function that does this; if so, I want to use the Haskell function name rather than inventing my own.
>
> Here is the function that I am implementing: consider a tree data structure. I pass to the function one of its leaf nodes. The function returns a list containing that leaf node as the first element of the list, the leaf node's parent as the second element of the list, ..., the tree's root node as the n'th element of the list. (The list consists of all the nodes from the leaf node to the root node)
>
> Does Haskell have a function that does this?
>
> If not, and you were to define a function for this, what name would you give to the function?
>
> /Roger
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
--
--
Regards,
KC
More information about the Beginners
mailing list