mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update and rename preorder_transversal.py to bt_preorder_transversal.py
This commit is contained in:
parent
7520042ef9
commit
84b35ceaf3
@ -2,9 +2,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
# recursive and iterative inorder traversal
|
|
||||||
|
|
||||||
def preorder_recursive(root: Optional[TreeNode]) -> list[int]:
|
def preorder_recursive(root: Optional[Node]) -> list[int]:
|
||||||
|
|
||||||
if root == None:
|
if root == None:
|
||||||
return []
|
return []
|
||||||
@ -12,7 +11,7 @@ def preorder_recursive(root: Optional[TreeNode]) -> list[int]:
|
|||||||
return [root.val] + preorder_recursive(root.left) + preorder_recursive(root.right)
|
return [root.val] + preorder_recursive(root.left) + preorder_recursive(root.right)
|
||||||
|
|
||||||
|
|
||||||
def preorder_iterative(root: Optional[TreeNode]) -> list[int]:
|
def preorder_iterative(root: Optional[Node]) -> list[int]:
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
stack = [root]
|
stack = [root]
|
Loading…
x
Reference in New Issue
Block a user