19 lines
437 B
Python
19 lines
437 B
Python
from dataclasses import dataclass
|
|
from enum import Enum, auto
|
|
from typing import Iterator, Optional
|
|
|
|
|
|
@dataclass
|
|
class Node[T]:
|
|
value: T
|
|
left: Optional['Node[T]']
|
|
right: Optional['Node[T]']
|
|
|
|
|
|
type BinaryTree[T] = Optional[Node[T]]
|
|
|
|
class TraversalType(Enum):
|
|
INORDER, POSTORDER, PREORDER = auto(), auto(), auto()
|
|
|
|
def traverse[T](tree: BinaryTree[T], order: TraversalType = TraversalType.INORDER) -> Iterator[T]:
|
|
pass |