Show pageOld revisionsBacklinksFold/unfold allBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Tree ====== <codeprism typescript> export function inorderTraversal<T>( root: node<T>, fn: (n: T) => boolean, newTree?: node<T> ) { newTree = { value: root.value, children: [], }; console.log(root.value); if (root.children) { for (const n of root.children) { if (fn(root.value)) { if (fn(n.value)) { newTree.children!.push(inorderTraversal(n, fn, newTree)); } else { for (const nn of n.children) { newTree.children!.push(inorderTraversal(nn, fn, newTree)); } } } } } return newTree; } </codeprism> data_structure.txt Last modified: 2024/05/26 13:05by root1