fix(curriculum): migrate data-structures setup from after-user-code (7 files) (#66484)

This commit is contained in:
Sem Bauke
2026-03-16 10:10:47 +01:00
committed by GitHub
parent 69b6fe3e0b
commit 946a88ca4f
7 changed files with 58 additions and 84 deletions
@@ -135,9 +135,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
BinarySearchTree.prototype = Object.assign(
@@ -193,6 +191,8 @@ BinarySearchTree.prototype = Object.assign(
);
```
# --seed--
## --seed-contents--
```js
@@ -163,9 +163,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
BinarySearchTree.prototype = Object.assign(
@@ -221,6 +219,8 @@ BinarySearchTree.prototype = Object.assign(
);
```
# --seed--
## --seed-contents--
```js
@@ -235,9 +235,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
BinarySearchTree.prototype = Object.assign(
@@ -320,6 +318,8 @@ BinarySearchTree.prototype = Object.assign(
);
```
# --seed--
## --seed-contents--
```js
@@ -89,9 +89,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
BinarySearchTree.prototype = Object.assign(
@@ -148,6 +146,8 @@ BinarySearchTree.prototype = Object.assign(
);
```
# --seed--
## --seed-contents--
```js
@@ -152,9 +152,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
DoublyLinkedList.prototype = Object.assign(
@@ -192,6 +190,8 @@ DoublyLinkedList.prototype = Object.assign(
});
```
# --seed--
## --seed-contents--
```js
@@ -66,13 +66,27 @@ assert(
if (typeof DoublyLinkedList !== 'undefined') {
test = new DoublyLinkedList();
}
test.add(58);
test.add(61);
test.add(32);
test.add(95);
test.add(41);
var n1 = new Node(58, null);
var n2 = new Node(61, n1);
var n3 = new Node(32, n2);
var n4 = new Node(95, n3);
var n5 = new Node(41, n4);
n1.next = n2;
n2.next = n3;
n3.next = n4;
n4.next = n5;
test.head = n1;
test.tail = n5;
test.reverse();
return test.print().join('') == '4195326158';
var result = [];
var current = test.head;
while (current) {
result.push(current.data);
current = current.next;
}
return result.join('') == '4195326158';
})()
);
```
@@ -86,73 +100,33 @@ assert(
if (typeof DoublyLinkedList !== 'undefined') {
test = new DoublyLinkedList();
}
test.add(11);
test.add(22);
test.add(33);
test.add(44);
test.add(55);
var n1 = new Node(11, null);
var n2 = new Node(22, n1);
var n3 = new Node(33, n2);
var n4 = new Node(44, n3);
var n5 = new Node(55, n4);
n1.next = n2;
n2.next = n3;
n3.next = n4;
n4.next = n5;
test.head = n1;
test.tail = n5;
test.reverse();
return test.printReverse().join('') == '1122334455';
var result = [];
var current = test.tail;
while (current) {
result.push(current.data);
current = current.prev;
}
return result.join('') == '1122334455';
})()
);
```
# --seed--
## --after-user-code--
```js
DoublyLinkedList.prototype = Object.assign(
DoublyLinkedList.prototype,
{
add(data) {
if (this.head == null) {
this.head = new Node(data, null);
this.tail = this.head;
} else {
var node = this.head;
var prev = null;
while (node.next != null) {
prev = node;
node = node.next;
};
var newNode = new Node(data, node);
node.next = newNode;
this.tail = newNode;
};
},
print() {
if (this.head == null) {
return null;
} else {
var result = new Array();
var node = this.head;
while (node.next != null) {
result.push(node.data);
node = node.next;
};
result.push(node.data);
return result;
};
},
printReverse() {
if (this.tail == null) {
return null;
} else {
var result = new Array();
var node = this.tail;
while (node.prev != null) {
result.push(node.data);
node = node.prev;
};
result.push(node.data);
return result;
};
}
}
);
```
## --seed-contents--
```js
@@ -57,9 +57,7 @@ assert(
);
```
# --seed--
## --after-user-code--
# --before-each--
```js
BinarySearchTree.prototype.push = function(val) {
@@ -93,6 +91,8 @@ BinarySearchTree.prototype.push = function(val) {
};
```
# --seed--
## --seed-contents--
```js