Published
Edited
Feb 14, 2020
2 forks
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(a, b, c).insert(d, c);
}
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(a, b, c).insert(d);
}
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(a, b, c).insert(d, a);
}
Insert cell
Insert cell
{
const d = new LinkedList.Node("D");
return LinkedList.of().insert(d);
}
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(a, b, d, c).remove(d);
}
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(d, a, b, c).remove(d);
}
Insert cell
Insert cell
{
const a = new LinkedList.Node("A");
const b = new LinkedList.Node("B");
const c = new LinkedList.Node("C");
const d = new LinkedList.Node("D");
return LinkedList.of(a, b, c, d).remove(d);
}
Insert cell
Insert cell
{
const d = new LinkedList.Node("D");
return LinkedList.of(d).remove(d);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(a, b, c).insert(d, c);
}
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(a, b, c).insert(d);
}
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(a, b, c).insert(d, a);
}
Insert cell
Insert cell
{
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of().insert(d);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(a, b, d, c).remove(d);
}
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(a, b, c, d).remove(d);
}
Insert cell
Insert cell
{
const a = new DoublyLinkedList.Node("A");
const b = new DoublyLinkedList.Node("B");
const c = new DoublyLinkedList.Node("C");
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(d, a, b, c).remove(d);
}
Insert cell
Insert cell
{
const d = new DoublyLinkedList.Node("D");
return DoublyLinkedList.of(d).remove(d);
}
Insert cell
Insert cell
LinkedList = {
class LinkedList {
static of(...nodes) {
const list = new LinkedList;
for (const node of nodes) list.insert(node);
return list;
}
constructor() {
this.head = null;
}
insert(node, where = null) {
node.next = where;
let prev = null, next = this.head;
while (next !== where) prev = next, next = next.next;
if (prev) prev.next = node;
else this.head = node;
return this;
}
remove(node) {
let prev = null, next = this.head;
while (next !== node) prev = next, next = next.next;
if (prev) prev.next = node.next;
else this.head = node.next;
node.next = null;
return this;
}
}
LinkedList.Node = class Node {
constructor(value) {
this.value = value;
this.next = null;
}
};
return LinkedList;
}
Insert cell
DoublyLinkedList = {
class DoublyLinkedList {
static of(...nodes) {
const list = new DoublyLinkedList;
for (const node of nodes) list.insert(node);
return list;
}
constructor() {
this.head = null;
this.tail = null;
}
insert(node, where = null) {
node.next = where;
node.prev = where ? where.prev : this.tail;
if (where === this.head) this.head = node;
if (where === null) this.tail = node;
if (node.prev) node.prev.next = node;
if (node.next) node.next.prev = node;
return this;
}
remove(node) {
if (node.next) node.next.prev = node.prev;
else this.tail = node.prev;
if (node.prev) node.prev.next = node.next;
else this.head = node.next;
node.next = null;
node.prev = null;
return this;
}
}
DoublyLinkedList.Node = class Node {
constructor(value) {
this.value = value;
this.next = null;
this.prev = null;
}
};
return DoublyLinkedList;
}
Insert cell
dot = require("@observablehq/graphviz@0.2")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more