Pop all items one by one . Do following for every popped item a ) append its right child and set its parent pointer b ) append its left child and set its parent pointer Note that right child is appended first so that left is processed first
while len ( nodeStack ) != 0 : NEW_LINE