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

Method nlrValues

data_structures/binary_search_tree.ts:663–672  ·  view source on GitHub ↗

* Create an iterator over this tree that traverses the tree in pre-order (NLR, * Node-Left-Right). * * @example Using the pre-order NLR iterator * ```ts * import { BinarySearchTree } from "@std/data-structures"; * import { assertEquals } from "@std/assert"; * * const tree = B

()

Source from the content-addressed store, hash-verified

661 * @returns An iterator that traverses the tree in pre-order (NLR).
662 */
663 *nlrValues(): IterableIterator<T> {
664 const nodes: BinarySearchNode<T>[] = [];
665 if (this.#root) nodes.push(this.#root);
666 while (nodes.length) {
667 const node: BinarySearchNode<T> = nodes.pop()!;
668 yield node.value;
669 if (node.right) nodes.push(node.right);
670 if (node.left) nodes.push(node.left);
671 }
672 }
673
674 /**
675 * Create an iterator over this tree that traverses the tree in post-order (LRN,

Callers 2

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected