class LinkedList extends Array {
constructor(...values) {
super(...values);
}
empty() {
return this.length == 0;
}
add(x) {
if (this.empty()) this.push(x, new LinkedList());
else [this[0], this[1]] = [x, new LinkedList(...this)];
}
remove() {
let nxt = this.next();
if (nxt.empty()) {
this.splice(0, 2);
} else [this[0], this[1]] = [nxt[0], nxt[1]];
}
value() {
return this[0];
}
next() {
return this[1];
}
find(x) {
let node = this;
while (!node.empty() && node.value() != x) node = node.next();
if (node.empty()) return null;
return node;
}
}