Skip to content

Commit ab11024

Browse files
committed
Improve examples
1 parent 0ad54c6 commit ab11024

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

JavaScript/2-five.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ function Node(parent, data) {
1010
this.data = data;
1111
this.parent = parent;
1212
this.count = 0;
13+
this.prev = null;
14+
this.next = null;
15+
this.first = null;
16+
this.last = null;
1317
if (parent) {
1418
this.tree = parent.tree;
1519
this.tree.count++;
16-
if (parent.count < 1) {
20+
if (!parent.count) {
1721
parent.first = this;
1822
}
1923
if (parent.last) {
@@ -23,10 +27,6 @@ function Node(parent, data) {
2327
parent.last = this;
2428
parent.count++;
2529
}
26-
this.prev = null;
27-
this.next = null;
28-
this.first = null;
29-
this.last = null;
3030
}
3131

3232
Node.prototype.add = function(data) {

JavaScript/5-bst.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tree.insert(root, 9);
3333
tree.insert(root, 2);
3434
tree.insert(root, 3);
3535
tree.insert(root, 1);
36+
console.dir(root);
3637

3738
const node = tree.search(root, 2);
3839
console.dir(node, { depth: 3 });

JavaScript/7-bst-over.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ tree.search = (root, data, value = root[0]) => (
1414
tree.search(root[data < value ? 1 : 2], data)
1515
);
1616

17-
tree.search = (root, data) => {
18-
const value = root[0];
19-
if (data === value) return root;
20-
const next = root[data < value ? 1 : 2];
21-
return next ? tree.search(next, data) : null;
22-
};
23-
2417
// Usage
2518

2619
const root = tree(5);

0 commit comments

Comments
 (0)