You are viewing a single comment's thread. Return to all comments →
python 3 def topView(root): queue=[] top_view={} queue.append([root,0]) while(queue): node,level=queue.pop(0) # to remove front element if level not in top_view: top_view[level]=node.info if node.left: node.left.level=level-1 queue.append((node.left, level - 1)) if node.right: node.right.level=level+1 queue.append((node.right, level + 1)) print(top_view) for level in sorted(top_view): print(top_view[level],end=" ")
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →