Module Expr Str Assign NameStore Str ClassDef bases body FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list decorator_list ClassDef bases body FunctionDef arguments args NameParam NameParam defaults body Expr Str If UnaryOpNot NameLoad body Return NameLoad Assign NameStore ListLoad NameLoad While NameLoad body Assign NameStore NameLoad Assign NameStore ListLoad For TupleStore NameStore NameStore Call NameLoad NameLoad body If AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr TryExcept body Assign AttributeStore NameLoad attr SubscriptLoad NameLoad Index BinOpAdd NameLoad Num handlers ExceptHandler type NameLoad body Assign AttributeStore NameLoad attr NameLoad decorator_list decorator_list
N/A N/A 
Follow up for problem "Populating Next Right Pointers in Each Node".

What if the given tree could be any binary tree? Would your previous solution still work?

Note:

You may only use constant extra space.
For example,
Given the following binary tree,
         1
       /        2    3
     / \        4   5    7
After calling your function, the tree should look like:
         1 -> NULL
       /        2 -> 3 -> NULL
     / \        4-> 5 -> 7 -> NULL
 N/A __author__ Danyang TreeNode N/A N/A __init__ N/A N/A self x N/A N/A N/A N/A self val x N/A N/A self left None N/A N/A self right None N/A N/A self next None N/A N/A Solution N/A N/A connect N/A N/A self root N/A N/A N/A 
        bfs
        same as Populating Next Right Pointers in Each Node I
        :param root: TreeNode
        :return: nothing
         N/A N/A root N/A N/A None N/A q N/A root N/A q N/A N/A current_level q N/A q N/A N/A N/A ind val N/A enumerate current_level N/A N/A N/A val left N/A N/A N/A N/A q append N/A val left N/A N/A val right N/A N/A N/A N/A q append N/A val right N/A N/A N/A N/A val next N/A current_level N/A N/A ind 1 N/A N/A N/A IndexError N/A N/A N/A val next None N/A N/A