MCPcopy Create free account
hub / github.com/denoland/std / lvlValues

Method lvlValues

data_structures/binary_search_tree.ts:726–735  ·  view source on GitHub ↗

* 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

()

Source from the content-addressed store, hash-verified

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,

Callers 2

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected