I have a binary tree and I need to get all sequences between the leaves and the root.
For example, for such tree
I need to get the sequences: "ABD", "ABE", "AC".
How to implement it? Thanks.
I have a binary tree and I need to get all sequences between the leaves and the root.
For example, for such tree
I need to get the sequences: "ABD", "ABE", "AC".
How to implement it? Thanks.
Pseudo code :
Function ProcessNode(TreeNode, ParentPath)
CurrentPath = Append(ParentPath, TreeNode.Name)
If IsNull(TreeNode.Left) And IsNull(TreeNode.Right) Then
Print(CurrentPath)
Else
If IsNotNull(TreeNode.Left) Then ProcessNode(TreeNode.Left, CurrentPath)
If IsNotNull(TreeNode.Right) Then ProcessNode(TreeNode.Right, CurrentPath)
ProcessNode(Root, "")