theme | transition | title | enableMenu | enableSearch | enableChalkboard | controls | slideNumber | hashOneBasedIndex |
---|---|---|---|---|---|---|---|---|
white |
slide |
Árvores e o DOM |
true |
false |
true |
true |
true |
false |
Luís Antônio (tonhao.dev)
function fib(n) {
if (n <= 2) return 1;
return fib(n - 1) + fib(n - 2);
}
fib(6)
class Node {
constructor(value) {
this.value = value;
this.children = [];
}
}
class Tree {
constructor(root) {
this.root = root;
}
}
class Tree {
...
insert(key, node) {
this.insertNode(this.root, key, node);
}
...
}
class Tree {
...
insertNode(currentNode, key, newNode) {
if (currentNode.value === key) {
currentNode.children.push(newNode);
return;
}
for (const node of currentNode.children) {
this.insertNode(node, key, newNode);
}
}
...
}
const tree = new Tree(new Node(1))
tree.insert(1, new Node(2))
tree.insert(1, new Node(3))
tree.insert(2, new Node(4))
tree.insert(2, new Node(5))
tree.insert(2, new Node(6))
tree.insert(5, new Node(7))
tree.insert(5, new Node(8))
tree.insert(3, new Node(9))