data_structure

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
data_structure [2024/05/26 11:08] – created root1data_structure [2024/05/26 13:05] (current) root1
Line 1: Line 1:
 ====== Tree ====== ====== Tree ======
 <codeprism typescript> <codeprism typescript>
-let anumber 1+export function inorderTraversal<T>
 +  rootnode<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> </codeprism>
  • data_structure.1716721705.txt.gz
  • Last modified: 2024/05/26 11:08
  • by root1