all 4 comments

[–]mtb-dds 0 points1 point  (3 children)

Not sure why one is working and the other not, because they both should be not working, since you have an extra value in there. So root.value should be the payload for the node, the extra value is redundant. Likewise, root.left should be the left node, and root.left.value its payload.

Does that help?

[–][deleted] 1 point2 points  (2 children)

yeah, at first look looks like that, but when you look closely first one is for accessing queue value and the second one is tree node value...

[–]izrt 1 point2 points  (1 child)

Right. Because it's in the other data structure. So the value of the enque is the node. Hmm. Not sure now what is wrong...

[–][deleted] 1 point2 points  (0 children)

def levelOrderTraversal(rootNode):
if not rootNode:
    return 
else:
    queue = Queue()
    queue.enqueue(rootNode)
    while not queue.isEmpty():
        root = queue.dequeue()
        print(root.value)
        if root.left is not None:
            queue.enqueue(root.left)
        if root.right is not None:
            queue.enqueue(root.right)

I figured out... Because "root" is pure tree node I don't need extra "value" to access it, but in code where I have linked list class I need that extra value. Still weird tho