mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
Delete bt_preorder_transversal.py
This commit is contained in:
parent
f7bc342551
commit
5eba7a1a80
1 changed files with 0 additions and 29 deletions
|
@ -1,29 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def preorder_recursive(root: Optional[Node]) -> list[int]:
|
||||
|
||||
if root is none None:
|
||||
return []
|
||||
|
||||
return [root.val] + preorder_recursive(root.left) + preorder_recursive(root.right)
|
||||
|
||||
|
||||
def preorder_iterative(root) -> list:
|
||||
|
||||
result = []
|
||||
stack = [root]
|
||||
|
||||
while stack:
|
||||
|
||||
node = stack.pop()
|
||||
|
||||
if node:
|
||||
result.append(node.val)
|
||||
stack.append(node.left)
|
||||
stack.append(node.right)
|
||||
|
||||
return result
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue