Socket
Socket
Sign inDemoInstall

data-structure-typed

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-structure-typed - npm Package Compare versions

Comparing version 1.16.1 to 1.17.0

255

dist/data-structures/linked-list/doubly-linked-list.d.ts

@@ -1,89 +0,216 @@

export declare class DoublyLinkedListNode<T> {
constructor(nodeValue: T);
protected _val: T;
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
export declare class DoublyLinkedListNode<T = number> {
/**
* The constructor function initializes the value, next, and previous properties of an object.
* @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
* is defined as a generic type "T".
*/
constructor(val: T);
private _val;
get val(): T;
set val(v: T);
protected _next: DoublyLinkedListNode<T> | null;
set val(value: T);
private _next;
get next(): DoublyLinkedListNode<T> | null;
set next(v: DoublyLinkedListNode<T> | null);
protected _prev: DoublyLinkedListNode<T> | null;
set next(value: DoublyLinkedListNode<T> | null);
private _prev;
get prev(): DoublyLinkedListNode<T> | null;
set prev(v: DoublyLinkedListNode<T> | null);
set prev(value: DoublyLinkedListNode<T> | null);
}
export declare class DoublyLinkedList<T> {
/**
* The constructor initializes the linked list with an empty head, tail, and length.
*/
constructor();
protected _first: DoublyLinkedListNode<T> | null;
get first(): DoublyLinkedListNode<T> | null;
protected set first(v: DoublyLinkedListNode<T> | null);
protected _last: DoublyLinkedListNode<T> | null;
get last(): DoublyLinkedListNode<T> | null;
protected set last(v: DoublyLinkedListNode<T> | null);
protected _size: number;
get size(): number;
protected set size(v: number);
private _head;
get head(): DoublyLinkedListNode<T> | null;
set head(value: DoublyLinkedListNode<T> | null);
private _tail;
get tail(): DoublyLinkedListNode<T> | null;
set tail(value: DoublyLinkedListNode<T> | null);
private _length;
get length(): number;
protected set length(value: number);
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
* given array.
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
* @returns The `fromArray` function returns a DoublyLinkedList object.
*/
getFirst(): DoublyLinkedListNode<T> | null;
static fromArray<T>(data: T[]): DoublyLinkedList<T>;
getLength(): number;
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The push function adds a new node with the given value to the end of the doubly linked list.
* @param {T} val - The value to be added to the linked list.
*/
getLast(): DoublyLinkedListNode<T> | null;
push(val: T): void;
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
* list is empty, it returns null.
*/
getSize(): number;
pop(): T | null;
/**
* The function adds a new node with a given value to the beginning of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
* the doubly linked list.
* @returns A boolean value is being returned.
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
* list.
*/
addFirst(val: T): boolean;
shift(): T | null;
/**
* The function adds a new node with a given value to the end of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
* doubly linked list.
* @returns a boolean value, which is always true.
*/
addLast(val: T): boolean;
peekFirst(): T | null;
peekFirst(by: 'val'): T | null;
peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
peekLast(): T | null;
peekLast(by: 'val'): T | null;
peekLast(by: 'node'): DoublyLinkedListNode<T> | null;
pollFirst(): T | null;
pollFirst(by: 'val'): T | null;
pollFirst(by: 'node'): DoublyLinkedListNode<T> | null;
pollLast(): T | null;
pollLast(by: 'val'): T | null;
pollLast(by: 'node'): DoublyLinkedListNode<T> | null;
get(index: number): T | null;
get(index: number, by: 'node'): DoublyLinkedListNode<T> | null;
get(index: number, by: 'val'): T | null;
unshift(val: T): void;
/**
* Updates the value of the node at the specified index.
* If index = 0; Value of the first element in the list is updated.
* If index = 3; Value of the fourth element in the list is updated.
* @param index Index of the node to be updated
* @param val New value of the node
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
* or the linked list is empty, it will return null.
*/
set(index: number, val: T): boolean;
isEmpty(): boolean;
getAt(index: number): T | null;
/**
* Inserts a new node at the specified index.
* @param index Index at which the new node has to be inserted
* @param val Value of the new node to be inserted
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
* range.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
* valid range of the linked list, otherwise it returns `null`.
*/
insert(index: number, val: T): boolean;
getNodeAt(index: number): DoublyLinkedListNode<T> | null;
/**
* The `remove` function removes an element at a specified index from a data structure, updating the links between
* nodes accordingly.
* @param {number} index - The index parameter represents the position of the element to be removed in the data
* structure. It is of type number.
* @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
* node if found, otherwise it returns null.
* @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
* is found in the linked list. If no such node is found, it returns `null`.
*/
findNode(val: T): DoublyLinkedListNode<T> | null;
/**
* The `insert` function inserts a value at a specified index in a doubly linked list.
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
* DoublyLinkedList. It is of type number.
* @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
* specified index.
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
* if the index is out of bounds.
*/
remove(index: number): T | null;
insert(index: number, val: T): boolean;
/**
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
* data structure. It is of type number.
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
* bounds.
*/
deleteAt(index: number): T | null;
/**
* The `delete` function removes a node with a specific value from a doubly linked list.
* @param {T} val - The `val` parameter represents the value that you want to delete from the linked list.
* @returns The `delete` method returns a boolean value. It returns `true` if the value `val` is found and deleted from
* the linked list, and `false` if the value is not found in the linked list.
*/
delete(val: T): boolean;
/**
* The `toArray` function converts a linked list into an array.
* @returns The `toArray()` method is returning an array of type `T[]`.
*/
toArray(): T[];
/**
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
*/
clear(): void;
/**
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `null`.
*/
find(callback: (val: T) => boolean): T | null;
/**
* The function returns the index of the first occurrence of a given value in a linked list.
* @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
* that we are searching for in the linked list.
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
* list. If the value is not found, it returns -1.
*/
indexOf(val: T): number;
/**
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
* value that satisfies the given callback function, or null if no value satisfies the callback.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a given value satisfies a certain condition.
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
* the callback function. If no value satisfies the condition, it returns `null`.
*/
findLast(callback: (val: T) => boolean): T | null;
/**
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
* @returns The `toArrayReverse()` function returns an array of type `T[]`.
*/
toArrayReverse(): T[];
/**
* The `reverse` function reverses the order of the elements in a doubly linked list.
*/
reverse(): void;
/**
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
* @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
* represents the value of the current node in the linked list, and the index argument represents the index of the
* current node in the linked list.
*/
forEach(callback: (val: T, index: number) => void): void;
/**
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
* DoublyLinkedList with the transformed values.
* @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
* DoublyLinkedList).
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
*/
map<U>(callback: (val: T) => U): DoublyLinkedList<U>;
/**
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
* elements that satisfy the given callback function.
* @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
* It is used to determine whether a value should be included in the filtered list or not.
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
*/
filter(callback: (val: T) => boolean): DoublyLinkedList<T>;
/**
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
* single value.
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
* used to perform a specific operation on each element of the linked list.
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
* point for the reduction operation.
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
* elements in the linked list.
*/
reduce<U>(callback: (accumulator: U, val: T) => U, initialValue: U): U;
/**
* The function inserts a new value after an existing value in a doubly linked list.
* @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
* @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert after
* the existing node.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
insertAfter(existingValue: T, newValue: T): boolean;
/**
* The `insertBefore` function inserts a new value before an existing value in a doubly linked list.
* @param {T} existingValue - The existing value is the value of the node that you want to insert the new value before.
* @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert before
* the existing node.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
insertBefore(existingValue: T, newValue: T): boolean;
}
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
var DoublyLinkedListNode = /** @class */ (function () {
function DoublyLinkedListNode(nodeValue) {
this._val = nodeValue;
/**
* The constructor function initializes the value, next, and previous properties of an object.
* @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
* is defined as a generic type "T".
*/
function DoublyLinkedListNode(val) {
this._val = val;
this._next = null;

@@ -14,4 +53,4 @@ this._prev = null;

},
set: function (v) {
this._val = v;
set: function (value) {
this._val = value;
},

@@ -25,4 +64,4 @@ enumerable: false,

},
set: function (v) {
this._next = v;
set: function (value) {
this._next = value;
},

@@ -36,4 +75,4 @@ enumerable: false,

},
set: function (v) {
this._prev = v;
set: function (value) {
this._prev = value;
},

@@ -47,13 +86,16 @@ enumerable: false,

var DoublyLinkedList = /** @class */ (function () {
/**
* The constructor initializes the linked list with an empty head, tail, and length.
*/
function DoublyLinkedList() {
this._first = null;
this._last = null;
this._size = 0;
this._head = null;
this._tail = null;
this._length = 0;
}
Object.defineProperty(DoublyLinkedList.prototype, "first", {
Object.defineProperty(DoublyLinkedList.prototype, "head", {
get: function () {
return this._first;
return this._head;
},
set: function (v) {
this._first = v;
set: function (value) {
this._head = value;
},

@@ -63,8 +105,8 @@ enumerable: false,

});
Object.defineProperty(DoublyLinkedList.prototype, "last", {
Object.defineProperty(DoublyLinkedList.prototype, "tail", {
get: function () {
return this._last;
return this._tail;
},
set: function (v) {
this._last = v;
set: function (value) {
this._tail = value;
},

@@ -74,8 +116,8 @@ enumerable: false,

});
Object.defineProperty(DoublyLinkedList.prototype, "size", {
Object.defineProperty(DoublyLinkedList.prototype, "length", {
get: function () {
return this._size;
return this._length;
},
set: function (v) {
this._size = v;
set: function (value) {
this._length = value;
},

@@ -86,288 +128,458 @@ enumerable: false,

/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
* given array.
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
* @returns The `fromArray` function returns a DoublyLinkedList object.
*/
DoublyLinkedList.prototype.getFirst = function () {
return this._first;
DoublyLinkedList.fromArray = function (data) {
var e_1, _a;
var doublyLinkedList = new DoublyLinkedList();
try {
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
var item = data_1_1.value;
doublyLinkedList.push(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
return doublyLinkedList;
};
DoublyLinkedList.prototype.getLength = function () {
return this._length;
};
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The push function adds a new node with the given value to the end of the doubly linked list.
* @param {T} val - The value to be added to the linked list.
*/
DoublyLinkedList.prototype.getLast = function () {
return this._last;
DoublyLinkedList.prototype.push = function (val) {
var newNode = new DoublyLinkedListNode(val);
if (!this.head) {
this.head = newNode;
this.tail = newNode;
}
else {
newNode.prev = this.tail;
this.tail.next = newNode;
this.tail = newNode;
}
this.length++;
};
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
* list is empty, it returns null.
*/
DoublyLinkedList.prototype.getSize = function () {
return this._size;
DoublyLinkedList.prototype.pop = function () {
if (!this.tail)
return null;
var removedNode = this.tail;
if (this.head === this.tail) {
this.head = null;
this.tail = null;
}
else {
this.tail = removedNode.prev;
this.tail.next = null;
}
this.length--;
return removedNode.val;
};
/**
* The function adds a new node with a given value to the beginning of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
* the doubly linked list.
* @returns A boolean value is being returned.
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
* list.
*/
DoublyLinkedList.prototype.addFirst = function (val) {
var newNode = new DoublyLinkedListNode(val);
if (this._size === 0) {
this._first = newNode;
this._last = newNode;
DoublyLinkedList.prototype.shift = function () {
if (!this.head)
return null;
var removedNode = this.head;
if (this.head === this.tail) {
this.head = null;
this.tail = null;
}
else {
if (this._first)
this._first.prev = newNode;
newNode.next = this._first;
this._first = newNode;
this.head = removedNode.next;
this.head.prev = null;
}
this._size++;
return true;
this.length--;
return removedNode.val;
};
/**
* The function adds a new node with a given value to the end of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
* @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
* doubly linked list.
* @returns a boolean value, which is always true.
*/
DoublyLinkedList.prototype.addLast = function (val) {
DoublyLinkedList.prototype.unshift = function (val) {
var newNode = new DoublyLinkedListNode(val);
if (this._size === 0) {
this._first = newNode;
this._last = newNode;
if (!this.head) {
this.head = newNode;
this.tail = newNode;
}
else {
if (this._last)
this._last.next = newNode;
newNode.prev = this._last;
this._last = newNode;
newNode.next = this.head;
this.head.prev = newNode;
this.head = newNode;
}
this._size++;
return true;
this.length++;
};
/**
* The `peekFirst` function returns the first node or value in a doubly linked list, depending on the specified
* parameter.
* @param {DoublyLinkedListGetBy} [by] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy. It
* is used to specify whether to return the first node, the value of the first node, or the first node itself.
* @returns The method `peekFirst` returns either the first node of the doubly linked list (`DoublyLinkedListNode<T>`),
* the value of the first node (`T`), or `null` depending on the value of the `by` parameter.
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
* or the linked list is empty, it will return null.
*/
DoublyLinkedList.prototype.peekFirst = function (by) {
var _a, _b, _c, _d, _e;
switch (by) {
case 'node':
return (_a = this._first) !== null && _a !== void 0 ? _a : null;
case 'val':
return (_c = (_b = this._first) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : null;
default:
return (_e = (_d = this._first) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
DoublyLinkedList.prototype.getAt = function (index) {
if (index < 0 || index >= this.length)
return null;
var current = this.head;
for (var i = 0; i < index; i++) {
current = current.next;
}
return current.val;
};
/**
* The `peekLast` function returns the last node or value in a doubly linked list.
* @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
* It specifies whether to return the last node, the value of the last node, or both. The default value is 'val', which
* means that if no value is provided for the "by" parameter, the method
* @returns The method `peekLast` returns the last node, value, or null based on the specified `by` parameter.
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
* range.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
* valid range of the linked list, otherwise it returns `null`.
*/
DoublyLinkedList.prototype.peekLast = function (by) {
var _a, _b, _c, _d, _e;
if (by === void 0) { by = 'val'; }
switch (by) {
case 'node':
return (_a = this._last) !== null && _a !== void 0 ? _a : null;
case 'val':
return (_c = (_b = this._last) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : null;
default:
return (_e = (_d = this._last) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
DoublyLinkedList.prototype.getNodeAt = function (index) {
if (index < 0 || index >= this.length)
return null;
var current = this.head;
for (var i = 0; i < index; i++) {
current = current.next;
}
return current;
};
/**
* The function `pollFirst` removes and returns the first element of a doubly linked list, either as a node or its
* value, depending on the specified parameter.
* @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
* It specifies the criteria by which the first element should be retrieved from the doubly linked list. The default
* value is 'val', which means the first element will be retrieved by its value. Other possible values for "by
* @returns The method `pollFirst` returns either the value of the first node in the doubly linked list, the first node
* itself, or null if the list is empty. The specific return type depends on the value of the `by` parameter. If `by`
* is set to 'node', the method returns the first node. If `by` is set to 'val', the method returns the value
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
* node if found, otherwise it returns null.
* @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
* is found in the linked list. If no such node is found, it returns `null`.
*/
DoublyLinkedList.prototype.pollFirst = function (by) {
var _a, _b, _c;
if (by === void 0) { by = 'val'; }
if (this._size === 0)
return null;
var oldHead = this._first;
if (this._size === 1) {
this._first = null;
this._last = null;
DoublyLinkedList.prototype.findNode = function (val) {
var current = this.head;
while (current) {
if (current.val === val) {
return current;
}
current = current.next;
}
else {
this._first = (_a = oldHead === null || oldHead === void 0 ? void 0 : oldHead.next) !== null && _a !== void 0 ? _a : null;
if (this._first)
this._first.prev = null;
if (oldHead)
oldHead.next = null;
return null;
};
/**
* The `insert` function inserts a value at a specified index in a doubly linked list.
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
* DoublyLinkedList. It is of type number.
* @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
* specified index.
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
* if the index is out of bounds.
*/
DoublyLinkedList.prototype.insert = function (index, val) {
if (index < 0 || index > this.length)
return false;
if (index === 0) {
this.unshift(val);
return true;
}
this._size--;
switch (by) {
case 'node':
return oldHead !== null && oldHead !== void 0 ? oldHead : null;
case 'val':
return (_b = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _b !== void 0 ? _b : null;
default:
return (_c = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _c !== void 0 ? _c : null;
if (index === this.length) {
this.push(val);
return true;
}
var newNode = new DoublyLinkedListNode(val);
var prevNode = this.getNodeAt(index - 1);
var nextNode = prevNode.next;
newNode.prev = prevNode;
newNode.next = nextNode;
prevNode.next = newNode;
nextNode.prev = newNode;
this.length++;
return true;
};
/**
* The function `pollLast` removes and returns the last element in a doubly linked list, either as a node or its value,
* depending on the specified parameter.
* @param {DoublyLinkedListGetBy} [by=val] - The parameter "by" is of type DoublyLinkedListGetBy, which is an enum that
* can have two possible values: 'node' or 'val'. It determines the type of value that will be returned by the pollLast
* method. If 'node' is specified, the method will return the
* @returns The method `pollLast` returns either a `DoublyLinkedListNode<T>`, the value of the node (`T`), or `null`.
* The specific type that is returned depends on the value of the `by` parameter. If `by` is set to `'node'`, then a
* `DoublyLinkedListNode<T>` is returned. If `by` is set to `'
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
* data structure. It is of type number.
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
* bounds.
*/
DoublyLinkedList.prototype.pollLast = function (by) {
var _a, _b, _c;
if (by === void 0) { by = 'val'; }
if (this._size === 0)
DoublyLinkedList.prototype.deleteAt = function (index) {
if (index < 0 || index >= this.length)
return null;
var polled = this._last;
if (this._size === 1) {
this._first = null;
this._last = null;
if (index === 0)
return this.shift();
if (index === this.length - 1)
return this.pop();
var removedNode = this.getNodeAt(index);
var prevNode = removedNode.prev;
var nextNode = removedNode.next;
prevNode.next = nextNode;
nextNode.prev = prevNode;
this.length--;
return removedNode.val;
};
/**
* The `delete` function removes a node with a specific value from a doubly linked list.
* @param {T} val - The `val` parameter represents the value that you want to delete from the linked list.
* @returns The `delete` method returns a boolean value. It returns `true` if the value `val` is found and deleted from
* the linked list, and `false` if the value is not found in the linked list.
*/
DoublyLinkedList.prototype.delete = function (val) {
var current = this.head;
while (current) {
if (current.val === val) {
if (current === this.head) {
this.shift();
}
else if (current === this.tail) {
this.pop();
}
else {
var prevNode = current.prev;
var nextNode = current.next;
prevNode.next = nextNode;
nextNode.prev = prevNode;
this.length--;
}
return true;
}
current = current.next;
}
else {
this._last = (_a = polled === null || polled === void 0 ? void 0 : polled.prev) !== null && _a !== void 0 ? _a : null;
if (this._last)
this._last.next = null;
if (polled)
polled.prev = null;
return false;
};
/**
* The `toArray` function converts a linked list into an array.
* @returns The `toArray()` method is returning an array of type `T[]`.
*/
DoublyLinkedList.prototype.toArray = function () {
var array = [];
var current = this.head;
while (current) {
array.push(current.val);
current = current.next;
}
this._size--;
switch (by) {
case 'node':
return polled !== null && polled !== void 0 ? polled : null;
case 'val':
return (_b = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _b !== void 0 ? _b : null;
default:
return (_c = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _c !== void 0 ? _c : null;
return array;
};
/**
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
*/
DoublyLinkedList.prototype.clear = function () {
this._head = null;
this._tail = null;
this._length = 0;
};
/**
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `null`.
*/
DoublyLinkedList.prototype.find = function (callback) {
var current = this.head;
while (current) {
if (callback(current.val)) {
return current.val;
}
current = current.next;
}
return null;
};
/**
* Returns the node at the specified index of the linked list.
* If index = 0; first element in the list is returned.
* If index = 3; fourth element in the list is returned.
* @param index Index of the node to be retrieved
* @param by Return value type
* The function returns the index of the first occurrence of a given value in a linked list.
* @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
* that we are searching for in the linked list.
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
* list. If the value is not found, it returns -1.
*/
DoublyLinkedList.prototype.get = function (index, by) {
var _a, _b;
if (by === void 0) { by = 'val'; }
if (index < 0 || index >= this._size)
return null;
var count, current;
if (index <= this._size / 2) {
count = 0;
current = this._first;
while (count !== index) {
current = current === null || current === void 0 ? void 0 : current.next;
count++;
DoublyLinkedList.prototype.indexOf = function (val) {
var index = 0;
var current = this.head;
while (current) {
if (current.val === val) {
return index;
}
index++;
current = current.next;
}
else {
count = this._size - 1;
current = this._last;
while (count !== index) {
current = current === null || current === void 0 ? void 0 : current.prev;
count--;
return -1;
};
/**
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
* value that satisfies the given callback function, or null if no value satisfies the callback.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a given value satisfies a certain condition.
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
* the callback function. If no value satisfies the condition, it returns `null`.
*/
DoublyLinkedList.prototype.findLast = function (callback) {
var current = this.tail;
while (current) {
if (callback(current.val)) {
return current.val;
}
current = current.prev;
}
switch (by) {
case 'node':
return current !== null && current !== void 0 ? current : null;
case 'val':
return (_a = current === null || current === void 0 ? void 0 : current.val) !== null && _a !== void 0 ? _a : null;
default:
return (_b = current === null || current === void 0 ? void 0 : current.val) !== null && _b !== void 0 ? _b : null;
return null;
};
/**
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
* @returns The `toArrayReverse()` function returns an array of type `T[]`.
*/
DoublyLinkedList.prototype.toArrayReverse = function () {
var array = [];
var current = this.tail;
while (current) {
array.push(current.val);
current = current.prev;
}
return array;
};
/**
* Updates the value of the node at the specified index.
* If index = 0; Value of the first element in the list is updated.
* If index = 3; Value of the fourth element in the list is updated.
* @param index Index of the node to be updated
* @param val New value of the node
* The `reverse` function reverses the order of the elements in a doubly linked list.
*/
DoublyLinkedList.prototype.set = function (index, val) {
var foundNode = this.get(index, 'node');
if (foundNode !== null) {
foundNode.val = val;
return true;
DoublyLinkedList.prototype.reverse = function () {
var _a, _b;
var current = this.head;
_a = __read([this.tail, this.head], 2), this.head = _a[0], this.tail = _a[1];
while (current) {
var next = current.next;
_b = __read([current.next, current.prev], 2), current.prev = _b[0], current.next = _b[1];
current = next;
}
return false;
};
DoublyLinkedList.prototype.isEmpty = function () {
return this._size === 0;
/**
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
* @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
* represents the value of the current node in the linked list, and the index argument represents the index of the
* current node in the linked list.
*/
DoublyLinkedList.prototype.forEach = function (callback) {
var current = this.head;
var index = 0;
while (current) {
callback(current.val, index);
current = current.next;
index++;
}
};
// --- start extra methods ---
/**
* Inserts a new node at the specified index.
* @param index Index at which the new node has to be inserted
* @param val Value of the new node to be inserted
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
* DoublyLinkedList with the transformed values.
* @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
* DoublyLinkedList).
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
*/
DoublyLinkedList.prototype.insert = function (index, val) {
if (index < 0 || index > this._size)
return false;
if (index === 0)
return !!this.addFirst(val);
if (index === this._size)
return !!this.addLast(val);
var newNode = new DoublyLinkedListNode(val);
var prevNode = this.get(index - 1, 'node');
var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
if (prevNode)
prevNode.next = newNode;
newNode.prev = prevNode;
newNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
if (nextNode)
nextNode.prev = newNode;
this._size++;
return true;
DoublyLinkedList.prototype.map = function (callback) {
var mappedList = new DoublyLinkedList();
var current = this.head;
while (current) {
mappedList.push(callback(current.val));
current = current.next;
}
return mappedList;
};
/**
* The `remove` function removes an element at a specified index from a data structure, updating the links between
* nodes accordingly.
* @param {number} index - The index parameter represents the position of the element to be removed in the data
* structure. It is of type number.
* @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
* if the index is out of bounds.
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
* elements that satisfy the given callback function.
* @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
* It is used to determine whether a value should be included in the filtered list or not.
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
*/
DoublyLinkedList.prototype.remove = function (index) {
var _a, _b, _c;
if (index < 0 || index > this._size - 1)
return null;
else if (index === 0)
return this.pollFirst();
else if (index === this._size - 1)
return (_b = (_a = this.pollLast('node')) === null || _a === void 0 ? void 0 : _a.val) !== null && _b !== void 0 ? _b : null;
else {
var prevNode = this.get(index - 1, 'node');
var removeNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
var nextNode = removeNode === null || removeNode === void 0 ? void 0 : removeNode.next;
if (prevNode)
prevNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
if (nextNode)
nextNode.prev = prevNode;
if (removeNode)
removeNode.next = null;
if (removeNode)
removeNode.prev = null;
this._size--;
return (_c = removeNode === null || removeNode === void 0 ? void 0 : removeNode.val) !== null && _c !== void 0 ? _c : null;
DoublyLinkedList.prototype.filter = function (callback) {
var filteredList = new DoublyLinkedList();
var current = this.head;
while (current) {
if (callback(current.val)) {
filteredList.push(current.val);
}
current = current.next;
}
return filteredList;
};
/**
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
* single value.
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
* used to perform a specific operation on each element of the linked list.
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
* point for the reduction operation.
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
* elements in the linked list.
*/
DoublyLinkedList.prototype.reduce = function (callback, initialValue) {
var accumulator = initialValue;
var current = this.head;
while (current) {
accumulator = callback(accumulator, current.val);
current = current.next;
}
return accumulator;
};
/**
* The function inserts a new value after an existing value in a doubly linked list.
* @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
* @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert after
* the existing node.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
DoublyLinkedList.prototype.insertAfter = function (existingValue, newValue) {
var existingNode = this.findNode(existingValue);
if (existingNode) {
var newNode = new DoublyLinkedListNode(newValue);
newNode.next = existingNode.next;
if (existingNode.next) {
existingNode.next.prev = newNode;
}
newNode.prev = existingNode;
existingNode.next = newNode;
if (existingNode === this.tail) {
this.tail = newNode;
}
this.length++;
return true;
}
return false;
};
/**
* The `insertBefore` function inserts a new value before an existing value in a doubly linked list.
* @param {T} existingValue - The existing value is the value of the node that you want to insert the new value before.
* @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert before
* the existing node.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
DoublyLinkedList.prototype.insertBefore = function (existingValue, newValue) {
var existingNode = this.findNode(existingValue);
if (existingNode) {
var newNode = new DoublyLinkedListNode(newValue);
newNode.prev = existingNode.prev;
if (existingNode.prev) {
existingNode.prev.next = newNode;
}
newNode.next = existingNode;
existingNode.prev = newNode;
if (existingNode === this.head) {
this.head = newNode;
}
this.length++;
return true;
}
return false;
};
return DoublyLinkedList;
}());
exports.DoublyLinkedList = DoublyLinkedList;

@@ -8,288 +8,173 @@ /**

*/
export declare class SinglyLinkedListNode<NodeVal = any> {
constructor(val: NodeVal, prev?: SinglyLinkedListNode<NodeVal> | null, next?: SinglyLinkedListNode<NodeVal> | null, list?: SinglyLinkedList<NodeVal> | null);
protected _val: NodeVal;
get val(): NodeVal;
set val(value: NodeVal);
protected _prev: SinglyLinkedListNode<NodeVal> | null;
get prev(): SinglyLinkedListNode<NodeVal> | null;
set prev(value: SinglyLinkedListNode<NodeVal> | null);
protected _next: SinglyLinkedListNode<NodeVal> | null;
get next(): SinglyLinkedListNode<NodeVal> | null;
set next(value: SinglyLinkedListNode<NodeVal> | null);
protected _list: SinglyLinkedList<NodeVal> | null;
get list(): SinglyLinkedList<NodeVal> | null;
set list(value: SinglyLinkedList<NodeVal> | null);
get index(): number | undefined;
export declare class SinglyLinkedListNode<T = number> {
/**
* The `insertBefore` function inserts a new node with the given value before the current node in a singly linked list.
* @param {NodeVal} val - The parameter "val" is of type "NodeVal". It represents the value of the node that you want
* to insert before the current node.
* @returns The method is returning a SinglyLinkedList<NodeVal>.
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
* @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
* will be stored in the node of a linked list.
*/
insertBefore(val: NodeVal): SinglyLinkedList<NodeVal>;
/**
* The function inserts a new node with the given value after the current node in a singly linked list.
* @param {NodeVal} val - The parameter `val` is the value of the node that you want to insert after the current node.
* @returns The method is returning a SinglyLinkedList<NodeVal>.
*/
insertAfter(val: NodeVal): SinglyLinkedList<NodeVal>;
/**
* The `remove()` function removes a node from a singly linked list.
* @returns The remove() method is returning a SinglyLinkedListNode<NodeVal> object.
*/
remove(): SinglyLinkedListNode<NodeVal>;
constructor(val: T);
private _val;
get val(): T;
set val(value: T);
private _next;
get next(): SinglyLinkedListNode<T> | null;
set next(value: SinglyLinkedListNode<T> | null);
}
export declare class SinglyLinkedList<NodeVal = any> {
export declare class SinglyLinkedList<T> {
/**
* The constructor initializes a linked list with the given arguments as nodes.
* @param {NodeVal[]} args - args is a rest parameter that allows the constructor to accept an arbitrary number of
* arguments of type NodeVal.
* The constructor initializes the linked list with an empty head, tail, and length.
*/
constructor(...args: NodeVal[]);
protected _head: SinglyLinkedListNode<NodeVal> | null;
get head(): SinglyLinkedListNode<NodeVal> | null;
set head(value: SinglyLinkedListNode<NodeVal> | null);
protected _tail: SinglyLinkedListNode<NodeVal> | null;
get tail(): SinglyLinkedListNode<NodeVal> | null;
set tail(value: SinglyLinkedListNode<NodeVal> | null);
protected _size: number;
get size(): number;
set size(value: number);
constructor();
private _head;
get head(): SinglyLinkedListNode<T> | null;
set head(value: SinglyLinkedListNode<T> | null);
private _tail;
get tail(): SinglyLinkedListNode<T> | null;
set tail(value: SinglyLinkedListNode<T> | null);
private _length;
get length(): number;
protected set length(value: number);
/**
* The `from` function in TypeScript creates a new SinglyLinkedList instance from an iterable object.
* @param iterable - The `iterable` parameter is an object that can be iterated over, such as an array or a string. It
* contains a collection of elements of type `T`.
* @returns The method is returning a new instance of the SinglyLinkedList class.
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
* array.
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
*/
static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
static fromArray<T>(data: T[]): SinglyLinkedList<T>;
getLength(): number;
/**
* The `get` function returns the value of a node at a given index in a data structure.
* @param {number} index - The index parameter is a number that represents the position of the node in the data
* structure.
* @returns The method is returning the value of the node at the specified index if the node exists, otherwise it
* returns undefined.
* The `push` function adds a new node with the given data to the end of a singly linked list.
* @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
* any type (T) as specified in the generic type declaration of the class or function.
*/
get(index: number): NodeVal | undefined;
push(data: T): void;
/**
* The function `getNode` returns the node at a given index in a singly linked list.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the linked list.
* @returns a SinglyLinkedListNode<NodeVal> object or undefined.
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
* pointers accordingly.
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
* the linked list is empty, it returns `null`.
*/
getNode(index: number): SinglyLinkedListNode<NodeVal> | undefined;
pop(): T | null;
/**
* The function `findNodeIndex` searches for a node in a singly linked list that satisfies a given condition and
* returns its index and the node itself.
* @param callbackFn - The callbackFn parameter is a function that takes three arguments: data, index, and list. It is
* used to determine whether a node in the singly linked list matches a certain condition. The function should return a
* boolean value indicating whether the condition is met for the given node.
* @returns The function `findNodeIndex` returns an object with two properties: `node` and `index`. The `node` property
* contains the node that matches the condition specified in the `callbackFn` function, and the `index` property
* contains the index of that node in the linked list. If no node matches the condition, the function returns
* `undefined`.
* The `shift()` function removes and returns the value of the first node in a linked list.
* @returns The value of the node that is being removed from the beginning of the linked list.
*/
findNodeIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): ({
node: SinglyLinkedListNode<NodeVal>;
index: number;
}) | undefined;
shift(): T | null;
/**
* The findNode function searches for a node in a singly linked list based on a given callback function.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the current node matches the desired criteria.
* @returns The function `findNode` returns a `SinglyLinkedListNode<NodeVal>` if a node satisfying the condition
* specified by the `callbackFn` is found in the linked list. If no such node is found, it returns `undefined`.
*/
findNode(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): SinglyLinkedListNode<NodeVal> | undefined;
/**
* The `find` function in TypeScript searches for a node in a singly linked list based on a given callback function and
* returns the value of the found node.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the condition is met for a particular node in the linked list.
* @returns The method `find` returns the `NodeVal` value of the first node in the linked list that satisfies the
* condition specified by the `callbackFn` function. If no node satisfies the condition, it returns `undefined`.
*/
find(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): NodeVal | undefined;
/**
* The findIndex function returns the index of the first node in a singly linked list that satisfies a given condition,
* or -1 if no such node is found.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the condition is met for a particular node in the singly linked list.
* @returns The method `findIndex` returns a number.
*/
findIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): number;
append(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
/**
* The push function appends multiple NodeVal objects to a data structure and returns the new size of the data
* structure.
* @param {NodeVal[]} args - args is a rest parameter of type NodeVal[]. It allows the function to accept any number
* of arguments of type NodeVal.
* @returns The size of the data structure after the nodes are appended.
*/
push(...args: NodeVal[]): number;
/**
* The `prepend` function adds new nodes to the beginning of a singly linked list.
* @param {NodeVal[]} args - An array of NodeVal objects.
* @returns The `prepend` method is returning the updated `SinglyLinkedList` object.
*/
prepend(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
/**
* The `insertAt` function inserts a value at a specified index in a singly linked list.
* @param {number} index - The index parameter is a number that represents the position at which the new node should be
* inserted in the linked list.
* @param {NodeVal} val - The `val` parameter represents the value of the node that you want to insert into the linked
* list.
* @returns The method `insertAt` returns the updated `SinglyLinkedList` object.
*/
insertAt(index: number, val: NodeVal): SinglyLinkedList<NodeVal>;
/**
* The removeNode function removes a node from a singly linked list and updates the head, tail, and size properties
* accordingly.
* @param node - The `node` parameter is of type `SinglyLinkedListNode<NodeVal>`, which represents a node in a singly
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
* @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
* linked list.
* @returns the removed node.
*/
removeNode(node: SinglyLinkedListNode<NodeVal>): SinglyLinkedListNode<NodeVal>;
unshift(val: T): void;
/**
* The `removeAt` function removes a node at a specified index from a singly linked list.
* @param {number} index - The index parameter is a number that represents the position of the node to be removed in
* the singly linked list.
* @returns The method `removeAt` returns a `SinglyLinkedListNode<NodeVal>` if the node at the specified index is
* found and removed successfully. If the node is not found, it returns `undefined`.
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
* `null` if the index is out of bounds.
*/
removeAt(index: number): SinglyLinkedListNode<NodeVal> | undefined;
getAt(index: number): T | null;
/**
* The `insertBefore` function inserts a new node with a given value before a specified reference node in a singly
* linked list.
* @param referenceNode - The referenceNode parameter is the node in the linked list before which the new node will be
* inserted.
* @param {NodeVal} val - The value of the new node that will be inserted before the reference node.
* @returns The method is returning the updated SinglyLinkedList object.
* The function `getNodeAt` returns the node at a given index in a singly linked list.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
* specified index exists, or `null` if the index is out of bounds.
*/
insertBefore(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
getNodeAt(index: number): SinglyLinkedListNode<T> | null;
/**
* The `sort` function uses the quicksort algorithm to sort the elements of a singly linked list based on a provided
* comparison function.
* @param start - The `start` parameter is the starting node of the sublist that needs to be sorted.
* @param end - The `end` parameter is a reference to the last node in the linked list. It is used as the pivot element
* for the quicksort algorithm.
* @returns The `sort` method is returning the sorted `SinglyLinkedList` object.
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
* data structure. It is of type number.
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
* bounds.
*/
sort(compare: (a: NodeVal, b: NodeVal) => boolean): SinglyLinkedList<NodeVal>;
deleteAt(index: number): T | null;
/**
* The `insertAfter` function inserts a new node with a given value after a specified reference node in a singly linked
* The `delete` function removes a specified value from a linked list and returns true if the value was found and
* removed, otherwise it returns false.
* @param {T} value - The value parameter represents the value of the node that needs to be deleted from the linked
* list.
* @param referenceNode - The referenceNode parameter is the node after which the new node will be inserted.
* @param {NodeVal} val - The value of the new node that will be inserted after the reference node.
* @returns The `insertAfter` method is returning the updated `SinglyLinkedList` object.
* @returns The `delete` method returns a boolean value. It returns `true` if the value was successfully deleted from
* the linked list, and `false` if the value was not found in the linked list.
*/
insertAfter(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
delete(value: T): boolean;
/**
* The `shift()` function removes and returns the first element from a linked list.
* @returns The `shift()` method is returning a value of type `NodeVal` or `undefined`.
* The `insert` function inserts a value at a specified index in a singly linked list.
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
* linked list. It is of type number.
* @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
* specified index.
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
* if the index is out of bounds.
*/
shift(): NodeVal | undefined;
insert(index: number, val: T): boolean;
/**
* The `pop()` function removes and returns the last element from a linked list.
* @returns The `pop()` method is returning a value of type `NodeVal` or `undefined`.
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
* whether it is empty or not.
* @returns A boolean value indicating whether the length of the object is equal to 0.
*/
pop(): NodeVal | undefined;
isEmpty(): boolean;
/**
* The merge function merges two singly linked lists by updating the next and prev pointers, as well as the head, tail,
* and size properties.
* @param list - The parameter "list" is a SinglyLinkedList object that contains nodes with data of type NodeVal.
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
*/
merge(list: SinglyLinkedList<NodeVal>): void;
clear(): void;
/**
* The clear() function resets the linked list by setting the head and tail to null and the size to 0.
* @returns The "this" object is being returned.
* The `toArray` function converts a linked list into an array.
* @returns The `toArray()` method is returning an array of type `T[]`.
*/
clear(): this;
toArray(): T[];
/**
* The `slice` function returns a new SinglyLinkedList containing a portion of the original list, starting from the
* specified index and ending at the optional end index.
* @param {number} start - The `start` parameter is a number that represents the index at which to start slicing the
* linked list.
* @param {number} [end] - The `end` parameter is an optional number that specifies the index at which to end the
* slicing. If no value is provided for `end`, or if the provided value is less than the `start` index, the slicing
* will continue until the end of the list.
* @returns a new SinglyLinkedList containing the sliced elements from the original list.
* The `reverse` function reverses the order of the nodes in a singly linked list.
* @returns The reverse() method does not return anything. It has a return type of void.
*/
slice(start: number, end?: number): SinglyLinkedList<NodeVal | {}>;
reverse(): void;
/**
* The reverse() function reverses the order of nodes in a singly linked list.
* @returns The reverse() method is returning the reversed SinglyLinkedList.
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `null`.
*/
reverse(): SinglyLinkedList<NodeVal>;
find(callback: (val: T) => boolean): T | null;
/**
* The `forEach` function iterates over a singly linked list and applies a callback function to each node, either in
* forward or reverse order.
* @param callbackFn - A callback function that will be called for each element in the linked list. It takes three
* parameters:
* @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
* to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
* (default), the iteration will start from the head and move towards the tail.
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
* @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
* value is not found, it returns -1.
*/
forEach(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): void;
indexOf(value: T): number;
/**
* The map function takes a callback function and applies it to each element in the linked list, returning a new linked
* list with the results.
* @param callbackFn - A callback function that will be applied to each element in the linked list. It takes three
* parameters:
* @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the mapping should be
* done in reverse order or not. If `reverse` is set to `true`, the mapping will be done in reverse order. If `reverse`
* is set to `false` or not provided, the mapping will be
* @returns The `map` function is returning a new `SinglyLinkedList` object.
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
* null.
* @param {T} value - The value parameter is the value that we want to search for in the linked list.
* @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
* the specified value is found, the function returns `null`.
*/
map(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
findNode(value: T): SinglyLinkedListNode<T> | null;
/**
* The `filter` function filters the elements of a singly linked list based on a given callback function.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It should return a
* boolean value indicating whether the current element should be included in the filtered list or not.
* @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the filtered list should
* be reversed or not. If `reverse` is set to `true`, the filtered list will be in reverse order. If `reverse` is set
* to `false` or not provided, the filtered list will be in
* @returns The `filter` method is returning a new `SinglyLinkedList` object.
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
* @param {T} existingValue - The existing value is the value that already exists in the linked list and before which
* we want to insert a new value.
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
* @returns The `insertBefore` function returns a boolean value. It returns `true` if the `newValue` is successfully
* inserted before the first occurrence of `existingValue` in the linked list. It returns `false` if the
* `existingValue` is not found in the linked list.
*/
filter(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
insertBefore(existingValue: T, newValue: T): boolean;
/**
* The `reduce` function iterates over a singly linked list and applies a callback function to each element,
* accumulating a single value.
* @param callbackFn - A callback function that will be called for each element in the linked list. It takes four
* parameters:
* @param {any} [start] - The `start` parameter is an optional initial value for the accumulator. If provided, the
* `reduce` function will start accumulating from this value. If not provided, the `reduce` function will use the value
* of the first element in the linked list as the initial value.
* @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
* to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
* (default), the iteration will start from the head and move towards the tail.
* @returns The `reduce` method returns the accumulated value after applying the callback function to each element in
* the linked list.
* The function inserts a new value after an existing value in a singly linked list.
* @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list
* after the node with the `existingValue`.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
reduce(callbackFn: (accumulator: any, currentNode: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => any, start?: any, reverse?: boolean): any;
insertAfter(existingValue: T, newValue: T): boolean;
/**
* The toArray() function converts a NodeVal object into an array of NodeVal objects.
* @returns An array of NodeVal objects.
* The function counts the number of occurrences of a given value in a linked list.
* @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
* @returns The count of occurrences of the given value in the linked list.
*/
toArray(): NodeVal[];
/**
* The `toString` function takes an optional separator and returns a string representation of an array, with each
* element separated by the specified separator.
* @param [separator= ] - The separator parameter is a string that specifies the character(s) to be used as a separator
* between each element in the array when converting it to a string. By default, the separator is set to a space
* character (' ').
* @returns The toString method is being returned as a string.
*/
toString(separator?: string): string;
/**
* The function is an iterator that returns the values of each node in a linked list.
*/
[Symbol.iterator](): IterableIterator<NodeVal>;
/**
* The function removes a node from either end of a singly linked list and returns its value.
* @param {SinglyLinkedListNode<NodeVal> | null} node - The `node` parameter is a reference to a node in a singly
* linked list. It can be either a `SinglyLinkedListNode` object or `null`.
* @returns The value of the removed node if the node is not null, otherwise undefined.
*/
protected removeFromAnyEnd(node: SinglyLinkedListNode<NodeVal> | null): NodeVal | undefined;
countOccurrences(value: T): number;
}
"use strict";
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};

@@ -52,32 +29,20 @@ var __read = (this && this.__read) || function (o, n) {

};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
/* The SinglyLinkedListNode class represents a node in a singly linked list and provides methods for inserting, removing,
and accessing nodes. */
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @license MIT License
*/
var SinglyLinkedListNode = /** @class */ (function () {
function SinglyLinkedListNode(val, prev, next, list) {
/**
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
* @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
* will be stored in the node of a linked list.
*/
function SinglyLinkedListNode(val) {
this._val = val;
this._prev = prev || null;
this._next = next || null;
this._list = list || null;
this._next = null;
}

@@ -94,12 +59,2 @@ Object.defineProperty(SinglyLinkedListNode.prototype, "val", {

});
Object.defineProperty(SinglyLinkedListNode.prototype, "prev", {
get: function () {
return this._prev;
},
set: function (value) {
this._prev = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SinglyLinkedListNode.prototype, "next", {

@@ -115,54 +70,2 @@ get: function () {

});
Object.defineProperty(SinglyLinkedListNode.prototype, "list", {
get: function () {
return this._list;
},
set: function (value) {
this._list = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SinglyLinkedListNode.prototype, "index", {
get: function () {
var _this = this;
if (!this.list) {
return undefined;
}
return this.list.findIndex(function (value) { return value === _this.val; });
},
enumerable: false,
configurable: true
});
/**
* The `insertBefore` function inserts a new node with the given value before the current node in a singly linked list.
* @param {NodeVal} val - The parameter "val" is of type "NodeVal". It represents the value of the node that you want
* to insert before the current node.
* @returns The method is returning a SinglyLinkedList<NodeVal>.
*/
SinglyLinkedListNode.prototype.insertBefore = function (val) {
return this.list !== null
? this.list.insertBefore(this, val)
: new SinglyLinkedList(val, this.val);
};
/**
* The function inserts a new node with the given value after the current node in a singly linked list.
* @param {NodeVal} val - The parameter `val` is the value of the node that you want to insert after the current node.
* @returns The method is returning a SinglyLinkedList<NodeVal>.
*/
SinglyLinkedListNode.prototype.insertAfter = function (val) {
return this.list !== null
? this.list.insertAfter(this, val)
: new SinglyLinkedList(this.val, val);
};
/**
* The `remove()` function removes a node from a singly linked list.
* @returns The remove() method is returning a SinglyLinkedListNode<NodeVal> object.
*/
SinglyLinkedListNode.prototype.remove = function () {
if (this.list === null) {
throw new ReferenceError('Node does not belong to any list');
}
return this.list.removeNode(this);
};
return SinglyLinkedListNode;

@@ -173,17 +76,8 @@ }());

/**
* The constructor initializes a linked list with the given arguments as nodes.
* @param {NodeVal[]} args - args is a rest parameter that allows the constructor to accept an arbitrary number of
* arguments of type NodeVal.
* The constructor initializes the linked list with an empty head, tail, and length.
*/
function SinglyLinkedList() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._head = null;
this._tail = null;
this._size = 0;
for (var i = 0; i < arguments.length; i++) {
this.append(args[i]);
}
this._length = 0;
}

@@ -210,8 +104,8 @@ Object.defineProperty(SinglyLinkedList.prototype, "head", {

});
Object.defineProperty(SinglyLinkedList.prototype, "size", {
Object.defineProperty(SinglyLinkedList.prototype, "length", {
get: function () {
return this._size;
return this._length;
},
set: function (value) {
this._size = value;
this._length = value;
},

@@ -222,122 +116,14 @@ enumerable: false,

/**
* The `from` function in TypeScript creates a new SinglyLinkedList instance from an iterable object.
* @param iterable - The `iterable` parameter is an object that can be iterated over, such as an array or a string. It
* contains a collection of elements of type `T`.
* @returns The method is returning a new instance of the SinglyLinkedList class.
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
* array.
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
*/
SinglyLinkedList.from = function (iterable) {
return new (SinglyLinkedList.bind.apply(SinglyLinkedList, __spreadArray([void 0], __read(iterable), false)))();
};
/**
* The `get` function returns the value of a node at a given index in a data structure.
* @param {number} index - The index parameter is a number that represents the position of the node in the data
* structure.
* @returns The method is returning the value of the node at the specified index if the node exists, otherwise it
* returns undefined.
*/
SinglyLinkedList.prototype.get = function (index) {
var node = this.getNode(index);
return node !== undefined ? node.val : undefined;
};
/**
* The function `getNode` returns the node at a given index in a singly linked list.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the linked list.
* @returns a SinglyLinkedListNode<NodeVal> object or undefined.
*/
SinglyLinkedList.prototype.getNode = function (index) {
if (this.head === null || index < 0 || index >= this.size) {
return undefined;
}
var asc = index < this.size / 2;
var stopAt = asc ? index : this.size - index - 1;
var nextNode = asc ? 'next' : 'prev';
var currentNode = asc ? this.head : this.tail;
// TODO after no-non-null-assertion not ensure the logic
for (var currentIndex = 0; currentIndex < stopAt; currentIndex++) {
if (currentNode) {
currentNode = currentNode[nextNode];
}
}
return currentNode || undefined;
};
/**
* The function `findNodeIndex` searches for a node in a singly linked list that satisfies a given condition and
* returns its index and the node itself.
* @param callbackFn - The callbackFn parameter is a function that takes three arguments: data, index, and list. It is
* used to determine whether a node in the singly linked list matches a certain condition. The function should return a
* boolean value indicating whether the condition is met for the given node.
* @returns The function `findNodeIndex` returns an object with two properties: `node` and `index`. The `node` property
* contains the node that matches the condition specified in the `callbackFn` function, and the `index` property
* contains the index of that node in the linked list. If no node matches the condition, the function returns
* `undefined`.
*/
SinglyLinkedList.prototype.findNodeIndex = function (callbackFn) {
var currentIndex = 0;
var currentNode = this.head;
while (currentNode) {
if (callbackFn(currentNode.val, currentIndex, this)) {
return {
index: currentIndex,
node: currentNode,
};
}
currentNode = currentNode.next;
currentIndex += 1;
}
return undefined;
};
/**
* The findNode function searches for a node in a singly linked list based on a given callback function.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the current node matches the desired criteria.
* @returns The function `findNode` returns a `SinglyLinkedListNode<NodeVal>` if a node satisfying the condition
* specified by the `callbackFn` is found in the linked list. If no such node is found, it returns `undefined`.
*/
SinglyLinkedList.prototype.findNode = function (callbackFn) {
var nodeIndex = this.findNodeIndex(callbackFn);
return nodeIndex !== undefined ? nodeIndex.node : undefined;
};
/**
* The `find` function in TypeScript searches for a node in a singly linked list based on a given callback function and
* returns the value of the found node.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the condition is met for a particular node in the linked list.
* @returns The method `find` returns the `NodeVal` value of the first node in the linked list that satisfies the
* condition specified by the `callbackFn` function. If no node satisfies the condition, it returns `undefined`.
*/
SinglyLinkedList.prototype.find = function (callbackFn) {
var nodeIndex = this.findNodeIndex(callbackFn);
return nodeIndex !== undefined ? nodeIndex.node.val : undefined;
};
/**
* The findIndex function returns the index of the first node in a singly linked list that satisfies a given condition,
* or -1 if no such node is found.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
* value indicating whether the condition is met for a particular node in the singly linked list.
* @returns The method `findIndex` returns a number.
*/
SinglyLinkedList.prototype.findIndex = function (callbackFn) {
var nodeIndex = this.findNodeIndex(callbackFn);
return nodeIndex !== undefined ? nodeIndex.index : -1;
};
/* The above code is a comment in TypeScript. It is using the triple hash symbol ( */
SinglyLinkedList.prototype.append = function () {
SinglyLinkedList.fromArray = function (data) {
var e_1, _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var singlyLinkedList = new SinglyLinkedList();
try {
for (var args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
var val = args_1_1.value;
var node = new SinglyLinkedListNode(val, this.tail, null, this);
if (this.head === null) {
this.head = node;
}
if (this.tail !== null) {
this.tail.next = node;
}
this.tail = node;
this.size += 1;
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
var item = data_1_1.value;
singlyLinkedList.push(item);
}

@@ -348,446 +134,363 @@ }

try {
if (args_1_1 && !args_1_1.done && (_a = args_1.return)) _a.call(args_1);
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
}
finally { if (e_1) throw e_1.error; }
}
return this;
return singlyLinkedList;
};
SinglyLinkedList.prototype.getLength = function () {
return this._length;
};
/**
* The push function appends multiple NodeVal objects to a data structure and returns the new size of the data
* structure.
* @param {NodeVal[]} args - args is a rest parameter of type NodeVal[]. It allows the function to accept any number
* of arguments of type NodeVal.
* @returns The size of the data structure after the nodes are appended.
* The `push` function adds a new node with the given data to the end of a singly linked list.
* @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
* any type (T) as specified in the generic type declaration of the class or function.
*/
SinglyLinkedList.prototype.push = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
SinglyLinkedList.prototype.push = function (data) {
var newNode = new SinglyLinkedListNode(data);
if (!this.head) {
this.head = newNode;
this.tail = newNode;
}
this.append.apply(this, __spreadArray([], __read(args), false));
return this.size;
else {
this.tail.next = newNode;
this.tail = newNode;
}
this.length++;
};
/**
* The `prepend` function adds new nodes to the beginning of a singly linked list.
* @param {NodeVal[]} args - An array of NodeVal objects.
* @returns The `prepend` method is returning the updated `SinglyLinkedList` object.
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
* pointers accordingly.
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
* the linked list is empty, it returns `null`.
*/
SinglyLinkedList.prototype.prepend = function () {
var e_2, _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
SinglyLinkedList.prototype.pop = function () {
if (!this.head)
return null;
if (this.head === this.tail) {
var val_1 = this.head.val;
this.head = null;
this.tail = null;
this.length--;
return val_1;
}
var reverseArgs = Array.from(args).reverse();
try {
for (var reverseArgs_1 = __values(reverseArgs), reverseArgs_1_1 = reverseArgs_1.next(); !reverseArgs_1_1.done; reverseArgs_1_1 = reverseArgs_1.next()) {
var val = reverseArgs_1_1.value;
var node = new SinglyLinkedListNode(val, null, this.head, this);
if (this.tail === null) {
this.tail = node;
}
if (this.head !== null) {
this.head.prev = node;
}
this.head = node;
this.size += 1;
}
var current = this.head;
while (current.next !== this.tail) {
current = current.next;
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (reverseArgs_1_1 && !reverseArgs_1_1.done && (_a = reverseArgs_1.return)) _a.call(reverseArgs_1);
}
finally { if (e_2) throw e_2.error; }
}
return this;
var val = this.tail.val;
current.next = null;
this.tail = current;
this.length--;
return val;
};
/**
* The `insertAt` function inserts a value at a specified index in a singly linked list.
* @param {number} index - The index parameter is a number that represents the position at which the new node should be
* inserted in the linked list.
* @param {NodeVal} val - The `val` parameter represents the value of the node that you want to insert into the linked
* list.
* @returns The method `insertAt` returns the updated `SinglyLinkedList` object.
* The `shift()` function removes and returns the value of the first node in a linked list.
* @returns The value of the node that is being removed from the beginning of the linked list.
*/
SinglyLinkedList.prototype.insertAt = function (index, val) {
if (this.head === null) {
return this.append(val);
}
if (index <= 0) {
return this.prepend(val);
}
var currentNode = this.head;
var currentIndex = 0;
while (currentIndex < index - 1 && currentNode.next !== null) {
currentIndex += 1;
currentNode = currentNode.next;
}
currentNode.insertAfter(val);
return this;
SinglyLinkedList.prototype.shift = function () {
if (!this.head)
return null;
var removedNode = this.head;
this.head = this.head.next;
this.length--;
return removedNode.val;
};
/**
* The removeNode function removes a node from a singly linked list and updates the head, tail, and size properties
* accordingly.
* @param node - The `node` parameter is of type `SinglyLinkedListNode<NodeVal>`, which represents a node in a singly
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
* @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
* linked list.
* @returns the removed node.
*/
SinglyLinkedList.prototype.removeNode = function (node) {
if (node.list !== this) {
throw new ReferenceError('Node does not belong to this list');
SinglyLinkedList.prototype.unshift = function (val) {
var newNode = new SinglyLinkedListNode(val);
if (!this.head) {
this.head = newNode;
this.tail = newNode;
}
if (node.prev !== null) {
node.prev.next = node.next;
else {
newNode.next = this.head;
this.head = newNode;
}
if (node.next !== null) {
node.next.prev = node.prev;
}
if (this.head === node) {
this.head = node.next;
}
if (this.tail === node) {
this.tail = node.prev;
}
this.size -= 1;
node.next = null;
node.prev = null;
node.list = null;
return node;
this.length++;
};
/**
* The `removeAt` function removes a node at a specified index from a singly linked list.
* @param {number} index - The index parameter is a number that represents the position of the node to be removed in
* the singly linked list.
* @returns The method `removeAt` returns a `SinglyLinkedListNode<NodeVal>` if the node at the specified index is
* found and removed successfully. If the node is not found, it returns `undefined`.
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
* `null` if the index is out of bounds.
*/
SinglyLinkedList.prototype.removeAt = function (index) {
var node = this.getNode(index);
return node !== undefined ? this.removeNode(node) : undefined;
SinglyLinkedList.prototype.getAt = function (index) {
if (index < 0 || index >= this.length)
return null;
var current = this.head;
for (var i = 0; i < index; i++) {
current = current.next;
}
return current.val;
};
/**
* The `insertBefore` function inserts a new node with a given value before a specified reference node in a singly
* linked list.
* @param referenceNode - The referenceNode parameter is the node in the linked list before which the new node will be
* inserted.
* @param {NodeVal} val - The value of the new node that will be inserted before the reference node.
* @returns The method is returning the updated SinglyLinkedList object.
* The function `getNodeAt` returns the node at a given index in a singly linked list.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
* specified index exists, or `null` if the index is out of bounds.
*/
SinglyLinkedList.prototype.insertBefore = function (referenceNode, val) {
var node = new SinglyLinkedListNode(val, referenceNode.prev, referenceNode, this);
if (referenceNode.prev === null) {
this.head = node;
SinglyLinkedList.prototype.getNodeAt = function (index) {
var current = this.head;
for (var i = 0; i < index; i++) {
current = current.next;
}
if (referenceNode.prev !== null) {
referenceNode.prev.next = node;
}
referenceNode.prev = node;
this.size += 1;
return this;
return current;
};
/**
* The `sort` function uses the quicksort algorithm to sort the elements of a singly linked list based on a provided
* comparison function.
* @param start - The `start` parameter is the starting node of the sublist that needs to be sorted.
* @param end - The `end` parameter is a reference to the last node in the linked list. It is used as the pivot element
* for the quicksort algorithm.
* @returns The `sort` method is returning the sorted `SinglyLinkedList` object.
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
* data structure. It is of type number.
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
* bounds.
*/
SinglyLinkedList.prototype.sort = function (compare) {
if (this.head === null || this.tail === null) {
return this;
}
if (this.size < 2) {
return this;
}
var quicksort = function (start, end) {
if (start === end) {
return;
}
var pivotData = end.val;
var current = start;
var split = start;
while (current && current !== end) {
var sort = compare(current.val, pivotData);
if (sort) {
if (current !== split) {
var temp = split.val;
split.val = current.val;
current.val = temp;
SinglyLinkedList.prototype.deleteAt = function (index) {
if (index < 0 || index >= this.length)
return null;
if (index === 0)
return this.shift();
if (index === this.length - 1)
return this.pop();
var prevNode = this.getNodeAt(index - 1);
var removedNode = prevNode.next;
prevNode.next = removedNode.next;
this.length--;
return removedNode.val;
};
/**
* The `delete` function removes a specified value from a linked list and returns true if the value was found and
* removed, otherwise it returns false.
* @param {T} value - The value parameter represents the value of the node that needs to be deleted from the linked
* list.
* @returns The `delete` method returns a boolean value. It returns `true` if the value was successfully deleted from
* the linked list, and `false` if the value was not found in the linked list.
*/
SinglyLinkedList.prototype.delete = function (value) {
var current = this.head;
var prev = null;
while (current) {
if (current.val === value) {
if (prev === null) {
this.head = current.next;
if (current === this.tail) {
this.tail = null;
}
// TODO after no-non-null-assertion not ensure the logic
if (split.next) {
split = split.next;
}
else {
prev.next = current.next;
if (current === this.tail) {
this.tail = prev;
}
}
current = current.next;
this.length--;
return true;
}
end.val = split.val;
split.val = pivotData;
if (start.next === end.prev) {
return;
}
if (split.prev && split !== start) {
quicksort(start, split.prev);
}
if (split.next && split !== end) {
quicksort(split.next, end);
}
};
quicksort(this.head, this.tail);
return this;
prev = current;
current = current.next;
}
return false;
};
/**
* The `insertAfter` function inserts a new node with a given value after a specified reference node in a singly linked
* list.
* @param referenceNode - The referenceNode parameter is the node after which the new node will be inserted.
* @param {NodeVal} val - The value of the new node that will be inserted after the reference node.
* @returns The `insertAfter` method is returning the updated `SinglyLinkedList` object.
* The `insert` function inserts a value at a specified index in a singly linked list.
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
* linked list. It is of type number.
* @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
* specified index.
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
* if the index is out of bounds.
*/
SinglyLinkedList.prototype.insertAfter = function (referenceNode, val) {
var node = new SinglyLinkedListNode(val, referenceNode, referenceNode.next, this);
if (referenceNode.next === null) {
this.tail = node;
SinglyLinkedList.prototype.insert = function (index, val) {
if (index < 0 || index > this.length)
return false;
if (index === 0) {
this.unshift(val);
return true;
}
if (referenceNode.next !== null) {
referenceNode.next.prev = node;
if (index === this.length) {
this.push(val);
return true;
}
referenceNode.next = node;
this.size += 1;
return this;
var newNode = new SinglyLinkedListNode(val);
var prevNode = this.getNodeAt(index - 1);
newNode.next = prevNode.next;
prevNode.next = newNode;
this.length++;
return true;
};
/**
* The `shift()` function removes and returns the first element from a linked list.
* @returns The `shift()` method is returning a value of type `NodeVal` or `undefined`.
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
* whether it is empty or not.
* @returns A boolean value indicating whether the length of the object is equal to 0.
*/
SinglyLinkedList.prototype.shift = function () {
return this.removeFromAnyEnd(this.head);
SinglyLinkedList.prototype.isEmpty = function () {
return this.length === 0;
};
/**
* The `pop()` function removes and returns the last element from a linked list.
* @returns The `pop()` method is returning a value of type `NodeVal` or `undefined`.
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
*/
SinglyLinkedList.prototype.pop = function () {
return this.removeFromAnyEnd(this.tail);
};
/**
* The merge function merges two singly linked lists by updating the next and prev pointers, as well as the head, tail,
* and size properties.
* @param list - The parameter "list" is a SinglyLinkedList object that contains nodes with data of type NodeVal.
*/
SinglyLinkedList.prototype.merge = function (list) {
if (this.tail !== null) {
this.tail.next = list.head;
}
if (list.head !== null) {
list.head.prev = this.tail;
}
this.head = this.head || list.head;
this.tail = list.tail || this.tail;
this.size += list.size;
list.size = this.size;
list.head = this.head;
list.tail = this.tail;
};
/**
* The clear() function resets the linked list by setting the head and tail to null and the size to 0.
* @returns The "this" object is being returned.
*/
SinglyLinkedList.prototype.clear = function () {
this.head = null;
this.tail = null;
this.size = 0;
return this;
this._head = null;
this._tail = null;
this._length = 0;
};
/**
* The `slice` function returns a new SinglyLinkedList containing a portion of the original list, starting from the
* specified index and ending at the optional end index.
* @param {number} start - The `start` parameter is a number that represents the index at which to start slicing the
* linked list.
* @param {number} [end] - The `end` parameter is an optional number that specifies the index at which to end the
* slicing. If no value is provided for `end`, or if the provided value is less than the `start` index, the slicing
* will continue until the end of the list.
* @returns a new SinglyLinkedList containing the sliced elements from the original list.
* The `toArray` function converts a linked list into an array.
* @returns The `toArray()` method is returning an array of type `T[]`.
*/
SinglyLinkedList.prototype.slice = function (start, end) {
var list = new SinglyLinkedList();
var finish = end;
if (this.head === null || this.tail === null) {
return list;
SinglyLinkedList.prototype.toArray = function () {
var array = [];
var current = this.head;
while (current) {
array.push(current.val);
current = current.next;
}
if (finish === undefined || finish < start) {
finish = this.size;
}
var head = this.getNode(start);
for (var i = 0; i < finish - start && head !== null && head !== undefined; i++) {
list.append(head.val);
head = head.next;
}
return list;
return array;
};
/**
* The reverse() function reverses the order of nodes in a singly linked list.
* @returns The reverse() method is returning the reversed SinglyLinkedList.
* The `reverse` function reverses the order of the nodes in a singly linked list.
* @returns The reverse() method does not return anything. It has a return type of void.
*/
SinglyLinkedList.prototype.reverse = function () {
var currentNode = this.head;
while (currentNode) {
var next = currentNode.next;
currentNode.next = currentNode.prev;
currentNode.prev = next;
currentNode = currentNode.prev;
var _a;
if (!this.head || this.head === this.tail)
return;
var prev = null;
var current = this.head;
var next = null;
while (current) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
var tail = this.tail;
this.tail = this.head;
this.head = tail;
return this;
_a = __read([this.tail, this.head], 2), this.head = _a[0], this.tail = _a[1];
};
/**
* The `forEach` function iterates over a singly linked list and applies a callback function to each node, either in
* forward or reverse order.
* @param callbackFn - A callback function that will be called for each element in the linked list. It takes three
* parameters:
* @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
* to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
* (default), the iteration will start from the head and move towards the tail.
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `null`.
*/
SinglyLinkedList.prototype.forEach = function (callbackFn, reverse) {
if (reverse === void 0) { reverse = false; }
var currentIndex = reverse ? this.size - 1 : 0;
var currentNode = reverse ? this.tail : this.head;
var modifier = reverse ? -1 : 1;
var nextNode = reverse ? 'prev' : 'next';
while (currentNode) {
callbackFn(currentNode.val, currentIndex, this);
currentNode = currentNode[nextNode];
currentIndex += modifier;
SinglyLinkedList.prototype.find = function (callback) {
var current = this.head;
while (current) {
if (callback(current.val)) {
return current.val;
}
current = current.next;
}
return null;
};
/**
* The map function takes a callback function and applies it to each element in the linked list, returning a new linked
* list with the results.
* @param callbackFn - A callback function that will be applied to each element in the linked list. It takes three
* parameters:
* @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the mapping should be
* done in reverse order or not. If `reverse` is set to `true`, the mapping will be done in reverse order. If `reverse`
* is set to `false` or not provided, the mapping will be
* @returns The `map` function is returning a new `SinglyLinkedList` object.
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
* @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
* value is not found, it returns -1.
*/
SinglyLinkedList.prototype.map = function (callbackFn, reverse) {
var _this = this;
if (reverse === void 0) { reverse = false; }
var list = new SinglyLinkedList();
this.forEach(function (val, index) { return list.append(callbackFn(val, index, _this)); }, reverse);
return list;
SinglyLinkedList.prototype.indexOf = function (value) {
var index = 0;
var current = this.head;
while (current) {
if (current.val === value) {
return index;
}
index++;
current = current.next;
}
return -1;
};
/**
* The `filter` function filters the elements of a singly linked list based on a given callback function.
* @param callbackFn - A callback function that takes three parameters: data, index, and list. It should return a
* boolean value indicating whether the current element should be included in the filtered list or not.
* @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the filtered list should
* be reversed or not. If `reverse` is set to `true`, the filtered list will be in reverse order. If `reverse` is set
* to `false` or not provided, the filtered list will be in
* @returns The `filter` method is returning a new `SinglyLinkedList` object.
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
* null.
* @param {T} value - The value parameter is the value that we want to search for in the linked list.
* @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
* the specified value is found, the function returns `null`.
*/
SinglyLinkedList.prototype.filter = function (callbackFn, reverse) {
var _this = this;
if (reverse === void 0) { reverse = false; }
var list = new SinglyLinkedList();
this.forEach(function (val, index) {
if (callbackFn(val, index, _this)) {
list.append(val);
SinglyLinkedList.prototype.findNode = function (value) {
var current = this.head;
while (current) {
if (current.val === value) {
return current;
}
}, reverse);
return list;
current = current.next;
}
return null;
};
/**
* The `reduce` function iterates over a singly linked list and applies a callback function to each element,
* accumulating a single value.
* @param callbackFn - A callback function that will be called for each element in the linked list. It takes four
* parameters:
* @param {any} [start] - The `start` parameter is an optional initial value for the accumulator. If provided, the
* `reduce` function will start accumulating from this value. If not provided, the `reduce` function will use the value
* of the first element in the linked list as the initial value.
* @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
* to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
* (default), the iteration will start from the head and move towards the tail.
* @returns The `reduce` method returns the accumulated value after applying the callback function to each element in
* the linked list.
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
* @param {T} existingValue - The existing value is the value that already exists in the linked list and before which
* we want to insert a new value.
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
* @returns The `insertBefore` function returns a boolean value. It returns `true` if the `newValue` is successfully
* inserted before the first occurrence of `existingValue` in the linked list. It returns `false` if the
* `existingValue` is not found in the linked list.
*/
SinglyLinkedList.prototype.reduce = function (callbackFn, start, reverse) {
if (reverse === void 0) { reverse = false; }
var currentIndex = reverse ? this.size - 1 : 0;
var modifier = reverse ? -1 : 1;
var nextNode = reverse ? 'prev' : 'next';
var currentElement = reverse ? this.tail : this.head;
var result;
if (start !== undefined) {
result = start;
SinglyLinkedList.prototype.insertBefore = function (existingValue, newValue) {
if (!this.head) {
return false;
}
else if (currentElement) {
result = currentElement.val;
currentElement = currentElement[nextNode];
if (this.head.val === existingValue) {
this.unshift(newValue);
return true;
}
else {
throw new TypeError('Reduce of empty LinkedList with no initial value');
var current = this.head;
while (current.next) {
if (current.next.val === existingValue) {
var newNode = new SinglyLinkedListNode(newValue);
newNode.next = current.next;
current.next = newNode;
this.length++;
return true;
}
current = current.next;
}
while (currentElement) {
result = callbackFn(result, currentElement.val, currentIndex, this);
currentIndex += modifier;
currentElement = currentElement[nextNode];
}
return result;
return false;
};
/**
* The toArray() function converts a NodeVal object into an array of NodeVal objects.
* @returns An array of NodeVal objects.
* The function inserts a new value after an existing value in a singly linked list.
* @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list
* after the node with the `existingValue`.
* @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
* existing value is not found in the linked list.
*/
SinglyLinkedList.prototype.toArray = function () {
return __spreadArray([], __read(this), false);
SinglyLinkedList.prototype.insertAfter = function (existingValue, newValue) {
var existingNode = this.findNode(existingValue);
if (existingNode) {
var newNode = new SinglyLinkedListNode(newValue);
newNode.next = existingNode.next;
existingNode.next = newNode;
if (existingNode === this.tail) {
this.tail = newNode;
}
this.length++;
return true;
}
return false;
};
/**
* The `toString` function takes an optional separator and returns a string representation of an array, with each
* element separated by the specified separator.
* @param [separator= ] - The separator parameter is a string that specifies the character(s) to be used as a separator
* between each element in the array when converting it to a string. By default, the separator is set to a space
* character (' ').
* @returns The toString method is being returned as a string.
* The function counts the number of occurrences of a given value in a linked list.
* @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
* @returns The count of occurrences of the given value in the linked list.
*/
SinglyLinkedList.prototype.toString = function (separator) {
if (separator === void 0) { separator = ' '; }
return this.reduce(function (s, val) { return "".concat(s).concat(separator).concat(val); });
};
/**
* The function is an iterator that returns the values of each node in a linked list.
*/
SinglyLinkedList.prototype[Symbol.iterator] = function () {
var element;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
element = this.head;
_a.label = 1;
case 1:
if (!(element !== null)) return [3 /*break*/, 3];
return [4 /*yield*/, element.val];
case 2:
_a.sent();
element = element.next;
return [3 /*break*/, 1];
case 3: return [2 /*return*/];
SinglyLinkedList.prototype.countOccurrences = function (value) {
var count = 0;
var current = this.head;
while (current) {
if (current.val === value) {
count++;
}
});
current = current.next;
}
return count;
};
/**
* The function removes a node from either end of a singly linked list and returns its value.
* @param {SinglyLinkedListNode<NodeVal> | null} node - The `node` parameter is a reference to a node in a singly
* linked list. It can be either a `SinglyLinkedListNode` object or `null`.
* @returns The value of the removed node if the node is not null, otherwise undefined.
*/
SinglyLinkedList.prototype.removeFromAnyEnd = function (node) {
return node !== null ? this.removeNode(node).val : undefined;
};
return SinglyLinkedList;
}());
exports.SinglyLinkedList = SinglyLinkedList;

@@ -12,6 +12,1 @@ import { BinaryTreeNode } from '../binary-tree';

export type ResultsByProperty<T> = ResultByProperty<T>[];
export interface BinaryTreeNodeObj<T> {
id: BinaryTreeNodeId;
val: T;
count?: number;
}
{
"name": "data-structure-typed",
"version": "1.16.1",
"version": "1.17.0",
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",

@@ -58,5 +58,3 @@ "main": "dist/index.js",

"typescript": "^4.9.5"
},
"dependencies": {
}
}

@@ -18,3 +18,3 @@ # What

## Live Examples
[API Docs](https://data-structure-typed-docs.vercel.app)

@@ -21,0 +21,0 @@ [Live Examples](https://data-structure-typed-examples.vercel.app)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc