import { tree } from "./tree" type BinaryNode = { value: T; left: BinaryNode | null; right: BinaryNode | null; }; // pre order function walk(current: BinaryNode | null, path: number[]): number[] { if (!current) { return path; } path.push(current.value); walk(current.left, path); walk(current.right, path); return path; } function pre_order_search(head: BinaryNode): number[] { const path: number[] = []; walk(head, path); return path; } test("Pre order", function () { expect(pre_order_search(tree)).toEqual([ 20, 10, 5, 7, 15, 50, 30, 29, 45, 100, ]); });