* Create an iterator over this tree that traverses the tree in level-order (BFS, * Breadth-First Search). * * @example Using the level-order BFS iterator * ```ts * import { BinarySearchTree } from "@std/data-structures"; * import { assertEquals } from "@std/assert"; * * const
()
| 724 | * @returns An iterator that traverses the tree in level-order (BFS). |
| 725 | */ |
| 726 | *lvlValues(): IterableIterator<T> { |
| 727 | const children: BinarySearchNode<T>[] = []; |
| 728 | let cursor: BinarySearchNode<T> | null = this.#root; |
| 729 | while (cursor) { |
| 730 | yield cursor.value; |
| 731 | if (cursor.left) children.push(cursor.left); |
| 732 | if (cursor.right) children.push(cursor.right); |
| 733 | cursor = children.shift() ?? null; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Create an iterator over this tree that traverses the tree in-order (LNR, |
no test coverage detected