* Create an iterator over this tree that traverses the tree in post-order (LRN, * Left-Right-Node). * * @example Using the post-order LRN iterator * ```ts * import { BinarySearchTree } from "@std/data-structures"; * import { assertEquals } from "@std/assert"; * * const tree =
()
| 688 | * @returns An iterator that traverses the tree in post-order (LRN). |
| 689 | */ |
| 690 | *lrnValues(): IterableIterator<T> { |
| 691 | const nodes: BinarySearchNode<T>[] = []; |
| 692 | let node: BinarySearchNode<T> | null = this.#root; |
| 693 | let lastNodeVisited: BinarySearchNode<T> | null = null; |
| 694 | while (nodes.length || node) { |
| 695 | if (node) { |
| 696 | nodes.push(node); |
| 697 | node = node.left; |
| 698 | } else { |
| 699 | const lastNode: BinarySearchNode<T> = nodes.at(-1)!; |
| 700 | if (lastNode.right && lastNode.right !== lastNodeVisited) { |
| 701 | node = lastNode.right; |
| 702 | } else { |
| 703 | yield lastNode.value; |
| 704 | lastNodeVisited = nodes.pop()!; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * Create an iterator over this tree that traverses the tree in level-order (BFS, |
no test coverage detected