UNPKG

@roger_npm_999/double-linked-list

Version:
54 lines (52 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ListNode = /** @class */ (function () { function ListNode(_value) { this.prev = exports.NULL_NODE; this.next = exports.NULL_NODE; this.value = null; this.value = _value; } /* Creates a new list node immediately after this node, erasing the chain at this point and re-creating it using the new node. Easiest way to implement insertion at point without index references */ ListNode.prototype.append = function (value) { var listNode = new ListNode(value); var eraseItr = this.next; while (eraseItr.value !== null) { this.list.size--; eraseItr.prev = exports.NULL_NODE; eraseItr.list = null; var itrNext = eraseItr.next; eraseItr = eraseItr.next; itrNext.next = exports.NULL_NODE; } this.next = listNode; listNode.prev = this; this.list.size++; this.list.tail = listNode; listNode.list = this.list; return listNode; }; ListNode.prototype.toString = function () { return JSON.stringify({ next: this.next.value, prev: this.prev.value, value: this.value }); }; return ListNode; }()); exports.ListNode = ListNode; // avoids circular dependency issue var NullNode = /** @class */ (function (_super) { tslib_1.__extends(NullNode, _super); function NullNode() { var _this = _super.call(this, null) || this; _this.prev = _this; _this.next = _this; return _this; } return NullNode; }(ListNode)); exports.NullNode = NullNode; exports.NULL_NODE = new NullNode();