Skip to content

DFS_recursive_inorder_btree in Julia would crash for singe-branch tree  #110

Closed
@jiegillet

Description

@jiegillet

In the code below, I think the case of single branch binary trees was not considered. It is checking >2 and >0 but not ==1 yet it uses [1]. We should add a case for single branch (which I realize is not well defined for here since we don't know if it's a left or right branch).

# This assumes only 2 children
function DFS_recursive_inorder_btree(n::Node)
if (length(n.children) > 2)
println("Not a binary tree!")
exit(1)
end
if (length(n.children) > 0)
DFS_recursive_inorder_btree(n.children[0])
println(n.ID)
DFS_recursive_inorder_btree(n.children[1])
else
println(n.ID)
end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProblemThis is a problem in the archive or an implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions