3 Object.defineProperty(exports, "__esModule", {
7 // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
8 // used for queues. This implementation assumes that the node provided by the user can be modified
9 // to adjust the next and last properties. We implement only the minimal functionality
12 this.head = this.tail = null;
16 function setInitial(dll, node) {
18 dll.head = dll.tail = node;
21 DLL.prototype.removeLink = function (node) {
22 if (node.prev) node.prev.next = node.next;else this.head = node.next;
23 if (node.next) node.next.prev = node.prev;else this.tail = node.prev;
25 node.prev = node.next = null;
30 DLL.prototype.empty = DLL;
32 DLL.prototype.insertAfter = function (node, newNode) {
34 newNode.next = node.next;
35 if (node.next) node.next.prev = newNode;else this.tail = newNode;
40 DLL.prototype.insertBefore = function (node, newNode) {
41 newNode.prev = node.prev;
43 if (node.prev) node.prev.next = newNode;else this.head = newNode;
48 DLL.prototype.unshift = function (node) {
49 if (this.head) this.insertBefore(this.head, node);else setInitial(this, node);
52 DLL.prototype.push = function (node) {
53 if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node);
56 DLL.prototype.shift = function () {
57 return this.head && this.removeLink(this.head);
60 DLL.prototype.pop = function () {
61 return this.tail && this.removeLink(this.tail);
63 module.exports = exports["default"];