Tree: Height of a Binary Tree

  • + 1 comment

    (JavaScript) Bug report on building a tree. For the example:

    7
    3 5 2 1 4 6 7
    

    It creates an _stdin_array = [ '7', '3 5 2 1 4 6 7' ] but the method readLine() tries to read n lines/elements after reding the first line(_stdin_array[0]) to assign the value to n but we only have one more line/element. Thus, the first node is created correctly because parseInt('3 5 2 1 4 6 7' ); but later tries to get _stdin_array[2] and _stdin_array[3] and so on, elements that not exists in the array and it gets an undefined and parseInt(undefined) returns a NaN. You end up with a right-loaded tree with mostly NaN data values.