Skip to content

Commit ef9685e

Browse files
authored
Merge pull request taizilongxu#48 from yinwoods/master
update 树的层次遍历
2 parents b1d68d9 + 76939ef commit ef9685e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Readme.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,14 +1664,10 @@ tree = Node(1, Node(3, Node(7, Node(0)), Node(6)), Node(2, Node(5), Node(4)))
16641664
```python
16651665

16661666
def lookup(root):
1667-
stack = [root]
1668-
while stack:
1669-
current = stack.pop(0)
1670-
print current.data
1671-
if current.left:
1672-
stack.append(current.left)
1673-
if current.right:
1674-
stack.append(current.right)
1667+
row = [root]
1668+
while row:
1669+
       print(row)
1670+
       row = [kid for item in row for kid in (item.left, item.right) if kid]
16751671

16761672
```
16771673

0 commit comments

Comments
 (0)