We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
(JavaScript) Bug report on building a tree. For the example:
73521467
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.
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
(JavaScript) Bug report on building a tree. For the example:
It creates an
_stdin_array = [ '7', '3 5 2 1 4 6 7' ]
but the methodreadLine()
tries to readn
lines/elements after reding the first line(_stdin_array[0]
) to assign the value ton
but we only have one more line/element. Thus, the first node is created correctly becauseparseInt('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 anundefined
andparseInt(undefined)
returns aNaN
. You end up with a right-loaded tree with mostlyNaN
data values.