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

Method lrnValues

data_structures/binary_search_tree.ts:690–708  ·  view source on GitHub ↗

* 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 =

()

Source from the content-addressed store, hash-verified

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,

Callers 2

Calls 3

pushMethod · 0.45
atMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected